>
> where the last evaluated statement is used as return value. This is
> specially useful for one-liners like the one below.


> Text {

      text: condition ? "A" : "B"

}


While we are on this topic, you may want to check out this article.

http://javascriptweblog.wordpress.com/2010/07/26/no-more-ifs-alternatives-to-statement-branching-in-javascript/

It gives an idea of some really cool tricks that you can do in JS


2010/9/15 Eduardo Fleury <[email protected]>

> Hi Pertti.
>
>
> 2010/9/15 Pertti Kellomäki <[email protected]>
>
>> Text {
>>    text: { if (condition) {
>>                  return "A";
>>               }
>>               return "B";
>>             }
>> }
>>
>> (...) in JavaScript, a return statement can only be used
>>
>> inside functions. Is the above syntax an extension of JavaScript, and if
>> so, is it documented somewhere?
>>
>
> My understanding is that in QML script blocks are implicit functions, and
> the above should be simply a more concise version of:
>
> Text {
>     function foobar() {
>
>         if (condition)
>             return "A";
>         return "B";
>     }
>
>     text: foobar()
> }
>
> Note that there's also a third valid version:
>
> Text {
>     text: {
>         if (condition)
>              "A"
>         else
>              "B"
>      }
> }
>
> where the last evaluated statement is used as return value. This is
> specially useful for one-liners like the one below.
>
> Text {
>       text: condition ? "A" : "B"
> }
>
> Cheers,
> Eduardo
>
> --
> Eduardo M. Fleury
> OpenBossa - INdT
> http://eduardofleury.com/
> http://www.openbossa.org/
>
> _______________________________________________
> Qt-qml mailing list
> [email protected]
> http://lists.trolltech.com/mailman/listinfo/qt-qml
>
>
_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.trolltech.com/mailman/listinfo/qt-qml

Reply via email to