Reminds 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…
How One Missing `var` Ruined our Launch
21–30 of 223 posts
Re: How One Missing `var` Ruined our Launch
#22jshint would have caught it. You need to run jshint on your code or you will get silly errors like this. Simple.
Re: How One Missing `var` Ruined our Launch
#23One thing you can do to help avoid this: use JSLint (or something equivalent) to check for missing var keywords. And, the obvious (as you already mentioned) coffeescript. Would love to hear of other suggestions on how to effectively debug this, especially in node.
Re: How One Missing `var` Ruined our Launch
#24> I would posit here that nothing I could do in best practice (manual front-end testing, unit testing, error handling, etc.) would have caught the offending line. jshint would have caught it. You need to run jshint on your code or you will get silly errors like this. Simple.
Re: How One Missing `var` Ruined our Launch
#25I feel for you man, but did you not test with more than one user at the same time? I live in constant fear of this kind of thing, I always round up as many people as possible to test at once.
Re: How One Missing `var` Ruined our Launch
#26Re: How One Missing `var` Ruined our Launch
#27Re: How One Missing `var` Ruined our Launch
#28Since everyone is chiming in with ways to prevent this sort of thing, here is another: js2 mode for Emacs[1]. This is a mode originally written by Steve Yegge and then modified by some other people (be sure to get that version) that actually parses the code and, among other things, highlights global variables in a different color than local ones. I find this, along with the other things js2 does, helps prevent a whol…
Re: How One Missing `var` Ruined our Launch
#29I just hit your page and it gave me an error that said the server was over capacity. Not the only reason?
Re: How One Missing `var` Ruined our Launch
#30> I would posit here that nothing I could do in best practice (manual front-end testing, unit testing, error handling, etc.) would have caught the offending line. jshint would have caught it. You need to run jshint on your code or you will get silly errors like this. Simple.
Even better is setting your editor to run JSHint when you save a .js file, and let you know if there are problems. Not only does it avoid stupid bugs, it saves time round-tripping to the browser for trivial issues like syntax errors.