Javascript Ternary Operator lvalue
I was reading about the ternary operator in different languages, and
noticed something interesting in the Javascript section.
http://en.wikipedia.org/wiki/%3F:#JavaScript
The first sentence states that the return of the ternary in javascript is
an lvalue, so I tried some examples, with odd results (in the chrome
console).
Given:
var a = { 'yo' : 'momma' }
var b = { 'yo' : 'cool' }
var bool = true
(bool? a : b).yo = 'LLJ'
//a is now { 'yo' : 'LLJ' }
(bool? a.yo : b.yo) = 'LLJ' //throws a reference error
Why does the first work and the second fail? (Logically they're the same
statements, no?)
No comments:
Post a Comment