Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-98195

Default function arguments have the wrong scope

XMLWordPrintable

      In ECMAScript, default function arguments are placed in their own environment record, which then acts as the parent scope for the function body. That means that

      console.log((function() {
              let a = 1;
              function f(fn = function(){ return a; }){ const a = 2; return fn() }
              return f();
          })())
      

      should print 1. However, in QML, it will print 2 because fn ends up in the scope of f's body, and thus uses the a from there instead of from the outer scope.

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

            qtqmlteam Qt Qml Team User
            fabiankosmale Fabian Kosmale
            Vladimir Minenko Vladimir Minenko
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:

                There are no open Gerrit changes