What does it mean: if (a=b)

P

pr

Joost Diepenmaat wrote:
[...]
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.
 
T

Thomas 'PointedEars' Lahn

pr said:
Joost Diepenmaat wrote:
[...]
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.

There is no standard-level edition of the ECMAScript Language Specification
that defines getters and setters yet, insofar your statement does not make
sense.

SpiderMonkey does work as specified for simple assignments that are backed
up by standard-level editions, e.g.:

var o = {
a: 1,
b: 3
};

// expect 3, get 3
window.alert(o.a = o.b);
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.

Nobody is talking about getters or setters except you.


PointedEars
 
P

pr

Thomas said:
pr said:
Joost Diepenmaat wrote:
[...]
Ecma-262,

11.13.1 Simple Assignment ( = )
[...]
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.

There is no standard-level edition of the ECMAScript Language Specification
that defines getters and setters yet, insofar your statement does not make
sense.

It is a bug. Brendan Eich says it is, and I figure he ought to know.

Unless E4X enjoys an unexpected renaissance, the most obvious way to
encounter it is when using getters and setters. It has never been
suggested, AFAIK, that the presence of these features should make
assignment behave in a non-standard way.
SpiderMonkey does work as specified for simple assignments that are backed
up by standard-level editions, e.g.:

var o = {
a: 1,
b: 3
};

// expect 3, get 3
window.alert(o.a = o.b);

And where it doesn't, it errs in fortunately trivial ways:

var a = [];
alert((a.length = "12") === "12"); // nope: it's become a number
Nobody is talking about getters or setters except you.

And?
 
T

Thomas 'PointedEars' Lahn

pr said:
Thomas said:
pr said:
Joost Diepenmaat wrote:
[...]
Ecma-262,

11.13.1 Simple Assignment ( = ) [...]
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.
There is no standard-level edition of the ECMAScript Language Specification
that defines getters and setters yet, insofar your statement does not make
sense.

It is a bug. Brendan Eich says it is, and I figure he ought to know.

You miss the point. It *is* a JavaScript bug; but it is not one to be filed
against SpiderMonkey *for violating the standard*, because there simply is
no standard to specify getters and setters yet. We are merely talking about
a proprietary, yet allowed, extension to ECMAScript here that happens to be
implemented (almost) the same in several script engines. Certainly nothing
you can rely on in a cross-browser context.
Unless E4X enjoys an unexpected renaissance, the most obvious way to
encounter it is when using getters and setters. It has never been
suggested, AFAIK, that the presence of these features should make
assignment behave in a non-standard way.

Irrelevant argument. It has never been suggested that proprietary features
have to behave in a standard way either.
SpiderMonkey does work as specified for simple assignments that are backed
up by standard-level editions, e.g.:

var o = {
a: 1,
b: 3
};

// expect 3, get 3
window.alert(o.a = o.b);

And where it doesn't, it errs in fortunately trivial ways:

var a = [];
alert((a.length = "12") === "12"); // nope: it's become a number

*That* is a bug to be filed against SpiderMonkey for violating the standard.

Although it is an interesting diversion, it does not have anything to do
with the problem at hand.


PointedEars
 
E

Evertjan.

Rick Merrill wrote on 29 mrt 2008 in comp.lang.javascript:
if ( 0 == Node.TEXT_NODE - n.nodeType ) and your readers won't have
to be told anything about the args.

Whose readers?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,281
Latest member
Pedroaciny

Latest Threads

Top