[Qt-qml] Semantics of 'return' in a JavaScript block in QML
Stephen Kelly
steveire at gmail.com
Wed Sep 29 12:50:54 CEST 2010
Sorry for dragging this up again. I forgot to reply at the time.
Pertti Kellomäki wrote:
> On 09/16/2010 03:37 AM, Kennedy Aaron (Nokia-MS-Qt/Brisbane) wrote:
>> Internally
>> the above is actually evaluated like this:
>>
>> Text {
>> text: (function() { if (condition) { return "A"; } return "B"; })()
>> }
>>
> This would actually be a good way to document it, at least to a former
> Lisp-head like myself ;-)
As a C++ head I rarely see syntax like the above and I find it quite
difficult to parse. I've seen stuff like that when reading jQuery.js and
code that uses it, but what is actually happening and why is it such a
common construct when using javascript? Got links?
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?
All the best,
Steve.
More information about the Qt-qml
mailing list