Uploaded image for project: 'Qbs ("Cubes")'
  1. Qbs ("Cubes")
  2. QBS-1227

Add Array.prototype.find() from ECMAScript 2015

    XMLWordPrintable

    Details

    • Type: Suggestion
    • Status: Reported
    • Priority: P4: Low
    • Resolution: Unresolved
    • Affects Version/s: 1.9.1
    • Fix Version/s: None
    • Component/s: API: JavaScript
    • Labels:
      None

      Description

      Qbs JavaScript engine supports methods such as some (check that some element matches the predicate), forEach (execute predicate for each element), every (check that all elements matches the predicate) etc. It does not support ECMAScript 2015 addition of `find` (return first element that matches the predicate). As per JavaScript documentation the workaround to define it ourselves and they even provide the implementation. However it would be nice if it was part of the engine as I believe it is quite useful and considerably shortens the code as otherwise one has to iterate over the array, check the value and return the element or break from the loop:

      var value;
      var array = [1,2,3,4,5];
      for(var i in array) {
          if(array[i] == 3) {
              value = array[i];
              break;
          }
      }
      

      vs

      var value = [1,2,3,4,5].find(function(element) { return element == 3; });
      

        Attachments

          Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

            Activity

              People

              Assignee:
              kandeler Christian Kandeler
              Reporter:
              resurr3ction Michael Vlach
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Dates

                Created:
                Updated:

                  Gerrit Reviews

                  There are no open Gerrit changes