On 2011-10-08, at 1:20 PM, chevalma@iro.umontreal.ca wrote:
It translates to X = X + Y, which is more intuitive, in a sense. That is what the operator is supposed to be a shorthand for.
Not really, because t[f(x)] += Y is not equal to
t[f(x)] = t[f(x)] + Y
It is equal to
{ int *loc = & t[f(x)]; *loc = *loc + Y; }
In other words, the semantics of X += Y (in C, etc) performs a single evaluation of X as an lvalue.
In JS, X is evaluated twice (once as an rvalue, possibly accessing the prototype, and a second time, as an lvalue, accessing the object itself). That is what is surprising.
Marc