3 ms·
A quick search of github gave this line: var undefined= undefined; Which has a comment explaining that it is an optimisation based on the idea that "define
by arethuza 13y ago
A quick search of github gave this line:
var undefined= undefined;
Which has a comment explaining that it is an optimisation based on the idea that "defined variables are faster than not-defined ones" - I have no idea if that is true or not.
https://github.com/Searle/mothello/blob/c31fc57bedd666e9da34c12d2f5068af80964899/v2/core.js https://github.com/Searle/mothello/blob/c31fc57bedd666e9da34...
I wonder if this counts as redefining undefined though!
The comment also suggests that jQuery does this, which seems to be true as explained in this link:
http://stackoverflow.com/questions/7141106/undefined-variable-in-jquery-code http://stackoverflow.com/questions/7141106/undefined-variabl...
"undefined in the jQuery code is actually an undefined parameter of a function wrapping the whole code"
Presumably if you have your own local undefined that is guaranteed to be undefined then you are safe from someone else setting it to be something silly.
Edit: The jQuery sources are all wrapped in:
(function( window, undefined ) {
...
})(window);
- moron4hire 13y agoIf you have to guard against someone doing something silly, then you are never safe. The problem is not the language at that point, it's the environment.
- MaulingMonkey 13y agoTo err is human -- you're never safe. Even if we say people are the root of the problem, fixing their fundamentally imperfect nature is currently beyond the capabilities of science, whereas doing something like enforcing constants at a language level is not. Education will reduce, but not eliminate, the chance of making such a mistake.
- epidemian 13y agoIt also allows minifiers to minify that "undefined" variable. Not that i think it's good practice to use those kind of hacks that gzip compression makes obsolete :P