The void of undefined in JavaScript
shapeshed.com
The void of undefined in JavaScript
1–10 of 34 posts
Re: The void of undefined in JavaScript
#2Re: The void of undefined in JavaScript
#3If someone redefined undefined and it causes a problem - too bad! Some problems are just too stupid to worry about.
Re: The void of undefined in JavaScript
#4And then it will be that persons' problem. Their code would be wrong, not mine. By not making sure my code works when undefined is broken, I would be helping them to realize they have a possible bug in their codebase and that they need to fix it.
Re: The void of undefined in JavaScript
#5Has anyone ever seen "undefined" be redefined, on one of their professional projects?
This seems like a solution in search of a problem.
Re: The void of undefined in JavaScript
#6Has anyone ever seen "undefined" be redefined, on one of their professional projects?
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/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-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);Re: The void of undefined in JavaScript
#7Has anyone ever seen "undefined" be redefined, on one of their professional projects?
Re: The void of undefined in JavaScript
#8> […] if you throw your scripts out there on the web you've got to expect that somewhere, at some time someone is going to do it […] And then it will be that persons' problem. Their code would be wrong, not mine. By not making sure my code works when undefined is broken, I would be helping them to realize they have a possible bug in their codebase and that they need to fix it.
And, yes, we know that other languages have flaws, too. But aside from perhaps PHP, the flaws in other languages are almost never as outright stupid as they are with JavaScript.
Re: The void of undefined in JavaScript
#9Has anyone ever seen "undefined" be redefined, on one of their professional projects?
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/c31fc57bedd666e9da34... I wonder if this counts as redefining undefined though! The comment also suggests that jQuery does this, which see…