Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default arguments for qml function gives syntax errors

Tags:

javascript

qt

qml

This code works fine in browser hosted JavaScript environment :

    function foo(a=true)
    {
        console.log(a)
    }

But doing the same in qml is giving syntax error.

What might I be doing wrong ?

like image 733
Amit Tomar Avatar asked May 23 '17 07:05

Amit Tomar


1 Answers

In QML, you should write the function as

function foo(a) {
    if (a === undefined) a = true

    console.log(a)
}

The syntax

function foo(a=true)

is not supported as this syntax was introduced in ECMA-262 6th edition while QML only implements the fifth edition (as of Qt 5.11).

like image 105
derM Avatar answered Oct 09 '22 22:10

derM