> Let's say someone is using your library within that function and you reference undefined. You get the string "oops". Oops indeed. That is incorrect. It might be correct if the word 'library' was replaced by 'code snippet' to indicate a copy-and-paste-of-your-code issue. But if you've created a library then your functions are over in some other file, where `typeof undefined === "undefined"`. The proper attitude here…
The void of undefined in JavaScript
21–30 of 34 posts
Re: The void of undefined in JavaScript
#22Has 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…
Re: The void of undefined in JavaScript
#23> Let's say someone is using your library within that function and you reference undefined. You get the string "oops". Oops indeed. That is incorrect. It might be correct if the word 'library' was replaced by 'code snippet' to indicate a copy-and-paste-of-your-code issue. But if you've created a library then your functions are over in some other file, where `typeof undefined === "undefined"`. The proper attitude here…
If `undefined` is an argument name, it's only bound inside that function and nowhere else.
Re: The void of undefined in JavaScript
#24The Crockford quote (characteristically dogmatic, to the effect of 'void means something different in JS than in Java, so AVOID VOID!') is also a kicker.
Re: The void of undefined in JavaScript
#25I guess my any languages are different. Never realized it's importain in haskell (except it is ⊥).
Re: The void of undefined in JavaScript
#26Re: The void of undefined in JavaScript
#27The correct solution for this problem of undefined is to do nothing! If 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
#28Re: The void of undefined in JavaScript
#29> […] 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.
This is one among many serious, and unjustifiable, flaws with JavaScript. It's the kind of issue that should never even arise with anyone's code in the first place, regardless of who wrote the code, because the language and its implementations should not allow it to happen. 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 stu…
Citation needed. There are tons of languages with huge fucking flaws to blow your code and kick your dog.
PHP and Javascript are relatively harmless (if a little brain damaged). At least you don't get buffer overflows using them.
You think C++ has a better design, for example? People forgot how bad Python used to be, pre 2.4?
Re: The void of undefined in JavaScript
#30> If you have done more than one day's programming in any language you will realise that this is an important building block for programmers. I guess my any languages are different. Never realized it's importain in haskell (except it is ⊥).