x ^= foo;
is effectively identical to
x = x ^ foo;
and the left operand 'x' is evaluated before 'foo', so any side effects in
'foo' do not affect the left operand.
(the order of evaluation is explicit in the ecmascript standard).

your statement is
x = x ^ (y = y ^ (x = x ^ y));
=>
x = 2 ^ (y = 1 ^ (x = 2 ^ 1));
=>
x = 3; x = 2 ^ (y = 1 ^ 3);
=>
x = 3; y = 2; x = 2 ^ 2;
=>
x = 3; y = 2; x = 0;


On Wed, Apr 1, 2015 at 3:38 PM, Mike Stay <[email protected]> wrote:

> I'd have thought that
>    x^=y^=x^=y;
> had the same meaning as
>    x = x ^ y;
>    y = y ^ x;
>    x = x ^ y;
> but when x is 1 and y is 2, in v8, spidermonkey, and rhino the short
> statement above sets x to 0 while the statements below set x to 2.
> What's actually happening?
> --
> Mike Stay - [email protected]
> http://www.cs.auckland.ac.nz/~mike
> http://reperiendi.wordpress.com
>
> --
>
> ---
> You received this message because you are subscribed to the Google Groups
> "Google Caja Discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/d/optout.
>

-- 

--- 
You received this message because you are subscribed to the Google Groups 
"Google Caja Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to