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

Using Function.bind in QML does lose global context

    XMLWordPrintable

Details

    Description

      When using Function.bind (MDN Function.bind) the global context is not attached to the returned function object, thus methods like eg. print can't be called anymore or console and Qt are not available.

       
      import QtQuick 2.0
      
      Rectangle {
          width: 360
          height: 360
      
          Component.onCompleted: {
              var func = test.bind(this, 1, 2);
              func();
          }
      
          function test(x, y) {
              print("this is just a test")
          }
      }
      

      The code above fails with
      ReferenceError: print is not defined

      Attachments

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

        Activity

          People

            416365416c Alan Alpert
            hhinrich Henrik Hinrichs
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes