I want to do something to a couple of variables using operators in quick succession. I don\'t think what I want to do is important as such; my question is more about th
According to ECMA-262 5th ed. 11.13.2,Compound Assignment Operators are evaluated as below:
- Let lref be the result of evaluating LeftHandSideExpression.
- Let lval be GetValue(lref).
- Let rref be the result of evaluating AssignmentExpression.
- Let rval be GetValue(rref).
- Let r be the result of applying operator @ to lval and rval.
- Throw a SyntaxError exception if the following conditions are all true: Type(lref) is Reference is true IsStrictReference(lref) is true Type(GetBase(lref)) is Environment Record
GetReferencedName(lref) is either "eval" or "arguments"- Call PutValue(lref, r).
- Return r.
The last example is evaluated as below:
1. Let a be lref, Let (b += (a += b)) be rlef.
2. Evaluate a and Let lval be the result of it(9).
3. Evaluate (b += (a += b)) and Let rval be the result of it.
a. Let b be lref_, Let (a += b) be rlef_.
b. Evaluate b and let lval_ be the result of it(2).
c. Evaluate (a += b) and let rval_ be the result of it.
A. Let a be lref__, let b be rlef.
B. Evaluate a and Let lval__ be the result of it(9).
C. Evaluate b and Let rval__ be the result of it(2).
D. Put lval__ + rval__ (means 9+2) to lref__(a) and return it.
d. Put lval_ + rval_ (means 2+11) to lref_(b) and return it.
4. Put lval + rval (means 9+13) to lref(a) and return it.
then we can get a === 22
, b === 13
.