Unsolved QML - Javascript: Does Javascript support EcmaScript 6?
-
Hi; I think Javascript for QML doesn't support ES6 (EcmaScript 6). Well, Is there any way for EcmaScript6 features? Thanks.
-
http://doc.qt.io/qt-5/qtqml-javascript-functionlist.html has some functions commented with
// ECMAScript 6:
Was there something specific?
-
@6thC thanks. I want to use arrow functions, default parameter values, rest parameters and spread operator. Are they possible?
-
@Ibrahim Is it too difficult to test it yourself? Add for example to any item in qml (example taken from your link):
Component.onCompleted: { var params = [ "hello", true, 7 ]; var other = [ 1, 2, ...params ]; // [ 1, 2, "hello", true, 7 ] var str = "foo"; var chars = [ ...str ]; // [ "f", "o", "o" ] }
and you will see if it works.
-
Arrow functions - not working:
// SyntaxError: Unexpected token `>' var sq = (x => x * x); sq(2);
Spread operator - not working.
// SyntaxError: Unexpected token `;' var str = "foo"; var chars = [ ...str ];
Ongoing unresolved bug:
-
Check this one... [EDIT: Non-Qt link removed --JKSH]
-
And for a noteworthy update: Qt 5.12 now supports ES6.
-
@GrecKo Support seems limited. I can't get arrow functions to work: https://forum.qt.io/topic/100526/what-parts-of-ecmascript-7-are-supported-in-qt-5-12
-
@GrecKo Never mind, I found your SO post explaining that I need to download the Qt Creator 4.9.0-beta2. That supports the new syntax.