[Qt-qml] Semantics of 'return' in a JavaScript block in QML

Caio Marcelo de Oliveira Filho caio.oliveira at openbossa.org
Wed Sep 29 13:37:49 CEST 2010


Hello,

>>> Text {
>>>      text: (function() { if (condition) { return "A"; } return "B"; })()

> It looks like a unnamed function is defined 'inline' inside some (), like a
> python lambda function or so, and then called immediately. Is that what's
> happening?

Yes. That's what's happening. The fact that the "function() { ... }"
is inside parentheses is to make sure javascript parser understand the
"function()" as a function expression.

A detailed explanation can be found here
http://stackoverflow.com/questions/1634268/explain-javascripts-encapsulated-anonymous-function-syntax

And since you asked for links, another resource that shows some
Javascript idiomatic code that you can find interesting is
http://ejohn.org/apps/learn/ ;-)


Cheers,

-- 
Caio Marcelo de Oliveira Filho
OpenBossa - INdT




More information about the Qt-qml mailing list