Javascript Containers Map, Set - supported?
-
Are Javascript containers like
Map
,Set
and member functions likeSet.has()
supported by QML Javascript? I'm getting errors like this:qrc:/CheckTypes.js:9: ReferenceError: Set is not defined qrc:/CheckTypes.js:31: TypeError: Cannot call method 'has' of undefined
"the QML runtime implements the ECMAScript Language Specification standard."
http://doc.qt.io/qt-5/qtqml-javascript-hostenvironment.html// CheckShapes.js .pragma library var shapes = new Set(["Circle", "Triangle", "Square"]); function isShape(polygon) { return shapes.has(polygon); }
// my.qml import QtQuick 2.9 import "qrc:/CheckShapes.js" as Foo RowLayout { id: bar visible: (Foo.isShape(myPolygon.name)); // Errors }; RowLayout { id: bar2 // This one works. visible: (myPolygon.name === "Circle" || myPolygon.name === "Triangle" || myPolygon.name === "Square"); }
My understanding is that QML fully supports the inclusion of JavaScript files. I've written a lengthy .js file to be imported and used within .qml files. My Javascript's rusty but syntax is mostly copy+pasted from Mozilla.org documentation.
Am I missing a declaration at the top of my .js file to import standard JavaScript types? A compiler flag in my QTCreator Kit? Syntax error?
--
Environment:
Apple MacOS: 10.13.3
QT Creator: 4.5.1 Based on 5.10.1 (Feb 10 2018, rev. 24cd0b1cd6)
Project: QT 5.9.2 -
Unfortumately, the QML engine does not support ECMAScript 2015 aka ES6.
The QML runtime implements the 5th edition of the standard
-
Unfortumately, the QML engine does not support ECMAScript 2015 aka ES6.
The QML runtime implements the 5th edition of the standard
Unfortumately, the QML engine does not support ECMAScript 2015 aka ES6.
@jpnurmiThank you @jpnurmi. Knowing JavaScript Frameworks exploded in popularity in the early 2000's I had no idea standard containers weren't added till 2015 nor that QML lagged that far behind the standard. Re-writing with arrays, my code fully doubled in size and went from near Constant Time to Linear. Disappointing. I guess that's just how it is.
-
Well, there is some it seems... just not all? I note there's quite a few comments: // ECMAScript 6 @: http://doc.qt.io/qt-5/qtqml-javascript-functionlist.html
While I've not used it - that page has:
map(callbackfn [, thisArg])
but not Set.. not sure if that helps...