tags:

views:

41

answers:

2

What happens when returnThis.label is referenced? Can one give me an example of how this might be used?

returnThis = {
        'label' : aLabel ? this.value : false
        };
+3  A: 

This makes use of ternary syntax.

aLabel ? this.value : false means: if aLabel is truthy (true, 1, "a", etc.), evaluate to this.value. Otherwise, evaulate to false.

The code is equivalent to the following:

returnThis = {};
if(aLabel) {
    returnThis.label = this.value;
} else {
    returnThis.label = false;
}
Matchu
so, please correct me if I am wrong...
cube
sorry. The usage of var newVAr=returnThis.label, will result in newVar having this.value if returnThis.label happens to be true?
cube
+3  A: 

Nothing happens (it just gets the value). The statement: aLabel ? this.value : false has already been executed.

Noon Silk