Steve Yeggae's js2-mode highlights globals during editing, and it's saved me a good many times. http://code.google.com/p/js2-mode/ Mind you it won't catch globals declared in chained assignments eg var x = y = 0; // y is defined globally
How One Missing `var` Ruined our Launch
211–220 of 223 posts
Re: How One Missing `var` Ruined our Launch
#212Actually it is very easy to debug any javascript error. In IE there is a setting where you can uncheck the Disable Script debugging (Internet Explorer) and in the status bar you will see any javascript error. If you check the checkbox IE will not report any errors. In general during your development you should always uncheck the box.If you double click the javascript status this will exactly report the line number wh…
Re: How One Missing `var` Ruined our Launch
#213I know there seem to be a few HN readers religiously against using an IDE, but in this case an IDE would have probably helped. Since it colors global and local variables differently the error would be much more apparent at the time when it was made (you typically have very few global variables so they stand out color wise).
Re: How One Missing `var` Ruined our Launch
#214I know there seem to be a few HN readers religiously against using an IDE, but in this case an IDE would have probably helped. Since it colors global and local variables differently the error would be much more apparent at the time when it was made (you typically have very few global variables so they stand out color wise).
No IDE needed - any decent editor will do syntax highlighting.
Re: How One Missing `var` Ruined our Launch
#215Reminds me of one of the more confusing bugs I've ever encountered in my life. I was throwing together a quick UI with Adobe Flex, and for some reason every time you clicked a particular button, the entire UI would shift 20 or so pixels to the right. I spent hours scratching my head until I noticed this for loop: for (x=0;x I wasn't declaring the x variable, so it was using the x part of the x/y positioning of the UI…
Now that I understand what you're saying: This is one of the reasons I hate the "feature" in C++ and C99 that you can declare variables anywhere. If you stick to declaring all your variables in one place, it's much easier to notice when you've already used a variable name.
Re: How One Missing `var` Ruined our Launch
#216This is why I really dislike it when I see var a = "foo", b = "bar", c = "baz"; All it takes is one missed comma and all of a sudden you've turned a lot of your variables global.
that's why many people favor this variant: var a = "foo" , b = "bar" , c = "baz" ;
var a = "foo";
var b = "bar";
var c = "baz";Re: How One Missing `var` Ruined our Launch
#217Re: How One Missing `var` Ruined our Launch
#218Earlier quoted context omitted.
Now there's an argument for syntax highlighting. It also doesn't happen in languages where you must say self.x to access a property/field called x .
Exactly my first thought: "This wouldn't happen with Python".
Only it is worse in Python because, lacking `var` keyword, you will shadow the variable in Python
Re: How One Missing `var` Ruined our Launch
#219 > (function () { internalvariablewithnovardelcaration = "string"; })();
> internalvariablewithnovardeclaration
ReferenceError: internalvariablewithnovardeclaration is not defined
at [object Context]:1:1
at Interface. (repl.js:179:22)
at Interface.emit (events.js:64:17)
at Interface._onLine (readline.js:153:10)
at Interface._line (readline.js:408:8)
at Interface._ttyWrite (readline.js:585:14)
at ReadStream. (readline.js:73:12)
at ReadStream.emit (events.js:81:20)
at ReadStream._emitKey (tty_posix.js:307:10)
at ReadStream.onData (tty_posix.js:70:12)
> externalwithnovar = 1;
1
> (function () { externalwithnovar = "string"; })();
> externalwithnovar
'string'
You're all wrong. There is no 'global by default for javascript. This guy clobbered a variable called initial outside of the scope of the callback.Re: How One Missing `var` Ruined our Launch
#220Am I right in thinking that the javascript /* "use strict" */ construct would have caught this mistake (just like it would have done for me in perl code)? Seems to me that some such feature is absolutely and utterly necessary in any environment where you're doing a lot of closure creation ..