I want to know if is possible to use optional parameters in a QML function.
I tried:
Code:
function danger(header, small, closeable = true) { setAlert(header, small, closeable) }
error: Syntax Error on closeable =
Printable View
I want to know if is possible to use optional parameters in a QML function.
I tried:
Code:
function danger(header, small, closeable = true) { setAlert(header, small, closeable) }
error: Syntax Error on closeable =
I think JavaScript lacks the notion of a default value for function arguments, but you can probably do something like this
Code:
setAlert(header, small, (typeof closeable !== 'undefined' ? closeable : true));
Cheers,
_
Or a shorthand of:
Code:
setAlert(header, small, closeable !== undefined ? closeable : true)