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

QML Javascript object property scope

    XMLWordPrintable

    Details

      Description

      Hello,

      recently I've bumped into non-standard JS engine behavior regarding Object scope that I could not find described neither in Qt Docs, nor in this bugtracker. Here is an example:

      var someFn1 = function () {};
      function someFn2 () {};
      var someObject = {
        someFn1: function() { console.log(this.someFn1 === someFn1) },
        someFn2: function() { console.log(this.someFn2 === someFn2) }
      }
      someObject.someFn1();
      someObject.someFn2();

      As per ES6 (and earlier versions) i expect both calls to result in console messages, both saying "false", but QML's Javascript engine clearly injects somehow inner someFn declarations into this very someObject block. I guess, that could be handy (everyone is annoyed with and often forgets "this." part), but now you can't reference an outside function with same name (and you will also get an error if the outside one is declared as const). Very unfortunately, third-party libs (that are valid in terms of ES6 syntax and otherwise fully supported by your Javascript engine) will also fail. Can you please clarify if it is a bug or a feature? It would be also great to have a quick note about that part in docs. Thanks a lot. 

        Attachments

          Issue Links

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

            Activity

              People

              Assignee:
              qt.team.quick.subscriptions Qt Quick and Widgets Team
              Reporter:
              kurumpa Kirill Mokhovtsev
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:

                  Gerrit Reviews

                  There are no open Gerrit changes