Open mattbierner opened 10 years ago
Actually, this is false.
Because of Javascript craziness, the toString
or valueOf
methods can do anything, including IO or state mutation. Therefore, it is generally not safe to switch the order in which two subexpressions with arbitrary objects are evaluated in.
Currently produces
Better output would be:
Because the order of evaluation of
10 + x
and2 * y
does not matter and we can directly replacey
in2 * y
with10 * x
. In other cases, this order is significant.Cannot be safely rewritten to
Because
f
could be crazy and mutatex
. Then the result of10 + x
may differ depending on if it is evaluated before or after the call tof
.