Isn't this whole issue just a minor version of the problem Ruby has with monkeypatching? The fact that a Ruby guy can define `method_missing` to allow for bare strings shows how Ruby is cool (though you should never do that), but the fact that you can redefine `undefined` in JS shows how JS is stupid (despite the fact that you should never do that). I don't understand the dichotomy.
The void of undefined in JavaScript
11–20 of 34 posts
Re: The void of undefined in JavaScript
#12One of the nice things about JavaScript is that it gives you the ability to accomplish things many different ways, but if someone uses that to shoot themselves in the foot then that is something they need to correct.
Re: The void of undefined in JavaScript
#13The 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
#14Isn't this whole issue just a minor version of the problem Ruby has with monkeypatching? The fact that a Ruby guy can define `method_missing` to allow for bare strings shows how Ruby is cool (though you should never do that), but the fact that you can redefine `undefined` in JS shows how JS is stupid (despite the fact that you should never do that). I don't understand the dichotomy.
People don't typically inject frequently changing, unvetted advertising code into their ruby runtimes. Generally, the most frequently that the ruby code in your runtime changes is each deploy.
This really boils down to "my code won't act the same way if I give unfettered access to my environment to unvetted code" which is true in almost any situation. If you're having problems because "undefined" is being redefined, you have bigger and more fundamental problems. There are a lot of bad things about JS, but this is not one of them - its overly nitpicky and completely unfair. This same capability (of being able to redefine almost anything) is lauded as part of Ruby, but when it could theoretically cause any easy-to-avoid problem in JS, it's just more proof that JS is a shitty language.
Sorry if I'm coming across as combative - I don't mean to. I just think this whole snide criticism of JS for every little thing is silly and unhelpful, and has more to do with a superiority complex than actual technical issues.
Re: The void of undefined in JavaScript
#15Re: The void of undefined in JavaScript
#16The 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.
indeed ... I'm surprised no one has mentioned "wat" yet :P https://www.destroyallsoftware.com/talks/wat
Re: The void of undefined in JavaScript
#17Has anyone ever seen "undefined" be redefined, on one of their professional projects?
Re: The void of undefined in JavaScript
#18That 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 is the same as the Python attitude towards not having `private` attributes: "If some other programmers want to do something crazy with my code, that's their prerogative. If it blows up in their faces, that's their problem."
Re: The void of undefined in JavaScript
#19Earlier quoted context omitted.
People don't typically inject frequently changing, unvetted advertising code into their ruby runtimes. Generally, the most frequently that the ruby code in your runtime changes is each deploy.
Granted, but that's an incidental problem, not one arising from JS being a bad language. Also, I highly doubt there is much advertising code that changes the value of "undefined" - certainly not any I've encountered. This really boils down to "my code won't act the same way if I give unfettered access to my environment to unvetted code" which is true in almost any situation. If you're having problems because "undefin…
In Ruby, nil, is a keyword so you can't assign to it nor can you use it as a method parameter.
Re: The void of undefined in JavaScript
#20 (function( window, undefined ) {
// ...
})( window );