P
pr
Joost Diepenmaat wrote:
[...]
It seems that Mozilla's implementation doesn't (yet) comply with the
specification (<URL:
https://bugzilla.mozilla.org/show_bug.cgi?id=312354>), For instance,
this script alerts the wrong value:
var o = {
get a() {return 1;}, set a(value) {return 2;},
get b() {return 3;}, set b(value) {return 4;}
};
alert(o.a = o.b); // expect 3, get 2
In Opera 9.5b and Safari 3.1 it gives the expected result.
This could make using getters and setters a little accident-prone, since
it follows that should a setter return no value, evaluating assignment
to that property would give 'undefined' in Firefox.
To produce a compliant result a setter must return the argument with
which it is called.
[...]
Ecma-262,
11.13.1 Simple Assignment ( = )
The production AssignmentExpression : LeftHandSideExpression =
AssignmentExpression is evaluated as follows:
1. Evaluate LeftHandSideExpression.
2. Evaluate AssignmentExpression.
3. Call GetValue(Result(2)).
4. Call PutValue(Result(1), Result(3)).
5. Return Result(3).
It seems that Mozilla's implementation doesn't (yet) comply with the
specification (<URL:
https://bugzilla.mozilla.org/show_bug.cgi?id=312354>), For instance,
this script alerts the wrong value:
var o = {
get a() {return 1;}, set a(value) {return 2;},
get b() {return 3;}, set b(value) {return 4;}
};
alert(o.a = o.b); // expect 3, get 2
In Opera 9.5b and Safari 3.1 it gives the expected result.
This could make using getters and setters a little accident-prone, since
it follows that should a setter return no value, evaluating assignment
to that property would give 'undefined' in Firefox.
To produce a compliant result a setter must return the argument with
which it is called.