On May 20, 2010, at 11:37 AM, Irakli Gozalishvili wrote:
Hi,
Sorry if my question is stupid or does not really belongs here. I
will be thankful to get some clarification on es specs since I just
discovered that my interpretation of how getter / setters are
supposed to behave appears to be different from the behavior in
observed in modern browsers.
var foo = Object.create({}, {
bar: {
get: function() {
return this._foo;
},
set: function(value) {
return this._foo = 'Hello ' + value;
}
}
});
var bar = foo.bar = 'setter';
if (foo.bar !== bar) throw new Error('Unexpected');
SpiderMonkey used to do what you want, since the dawn of time (1995,
the first JS runtime, "Mocha"). The result of evaluating an assignment
expression was the return value of the setter, not the result of
evaluating the right-hand-side expression. We changed to track
ECMA-262 (IIRC Acid3 actually tested this and dinged us).
The code will throw an error cause bar will be 'setter' while
foo.bar will be 'Hello setter'. I was expecting that `bar' would've
get value returned by a setter (or at least getter of foo). And this
is not the case nor with FF nor with Safari implementations.
Behavior is the same if getters and setters are used instead.
I'm not sure what you mean -- do you mean Firefox and Safari ignore
the setter's return value? That's what my testing with Firefox 3.6.x
and Safari 4 show, on this HTML source:
<script>
var foo = {
get bar() {
return this._foo;
},
set bar(value) {
return this._foo = 'Hello ' + value;
}
};
var bar = foo.bar = 'setter';
alert('bar ' + bar + ', foo.bar ' + foo.bar);
</script>
Is it expected behavior ? If answer is yes, is there any point of
returning anything from setter ?
No point now.
I am also afraid that this might break some of the frameworks in
rare cases like in this example above. (a = b = c is commonly used
syntax)
No browser does what we used to do, so any framework counting on
setters filtering
_______________________________________________
es-discuss mailing list
es-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es-discuss