According to the spec (Annex C), strict-mode code can't do pretty much anything that might assign any identifier with the name eval
. I can understand that one might want to restrict use of the actual eval
function, but I don't see what purpose is served by restricting use of the name?
views:
105answers:
1I can only speculate, but it seems to me that ES5-strict is saying that eval
and arguments
should be considered as raw syntax, not identifiers. It is reasonable that these two features should be implemented at the syntactical level, because they have Amazing Funky Magic behaviours that cannot be reproduced by a normal function.
(In particular eval
may write to local variables in the function that calls it, and writing to arguments
bizarrely changes the values of local variables corresponding to the arguments. Though this behaviour seems to be going away in strict mode, thankfully.)
For compatibility reasons, ES5 can't actually make eval
and arguments
syntactical. So they do the nearest they can, which is to say that the identifier arguments
always refers to arguments
magic and the identifier eval
always exclusively refers to eval
magic.
It could also improve the possibilities for optimisation, if JS engines can be sure whether a function contains magic.