News for hackers. Stuff that matters.
Re:The void of undefined in JavaScript by ChrisAntaki on Friday July 12, 2013 @07:22AM (#6032011)
Has anyone ever seen "undefined" be redefined, on one of their professional projects?
Re:The void of undefined in JavaScript by arethuza on Friday July 12, 2013 @07:55AM (#6032110)
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 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 by epidemian on Friday July 12, 2013 @11:24AM (#6033063)
It 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
Re:The void of undefined in JavaScript by moron4hire on Friday July 12, 2013 @08:20AM (#6032178)
If 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.
Re:The void of undefined in JavaScript by MaulingMonkey on Saturday July 13, 2013 @03:41PM (#6038481)
To 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.
Re:The void of undefined in JavaScript by ars on Friday July 12, 2013 @07:53AM (#6032102)
Has anyone ever seen "undefined" be redefined on anything ever?

This seems like a solution in search of a problem.

Re:The void of undefined in JavaScript by PommeDeTerre on Friday July 12, 2013 @08:03AM (#6032130)
It does happen. I worked with one team several years back that had inherited some particularly bad JavaScript code, and this was an issue they ran into several times. They ended up having to audit all of the code for nonsense like this before they could proceed with actual work.