Ouch. That really sucks. I'm glad you figured it out.
I wonder what you could have done to find the bug before it was a serious problem? Most server side errors are easy because you can configure alert emails. Subtle data corruption or client side bugs are much harder to pin point as they manifest much further down the pipe in unintuitive ways.
Subtle data corruption bugs aside, is there someway to handle client side bugs? I'm no Javascript expert, but I'd imagine there has got to be a way to register a global on-error handler and post bug reports to the server? Any expert insight here?
He could have run it through JSLint. It catches not wrapping the body of a for-in block in a hasOwnProperty conditional.
Example:
var arr = [0,1,2,3,4,5];
for(var p in arr) { console.log(arr[p]); }
Array.prototype.foo = "bar";
for(var p in arr) {
if(arr.hasOwnProperty(p)) {
console.log(arr[p]);
}
}
for(var p in arr) { console.log(arr[p]); }
If you run this in firebug's console, you'll notice that the first two loops work as expected, even after changing the prototype of the Array object. The third one, however, will spit out "bar" as well.
JSLint can be mean to your code, but it helps catch an enormous amount of small bugs like this caused by JS's warts.
I wonder what you could have done to find the bug before it was a serious problem? Most server side errors are easy because you can configure alert emails. Subtle data corruption or client side bugs are much harder to pin point as they manifest much further down the pipe in unintuitive ways.
Subtle data corruption bugs aside, is there someway to handle client side bugs? I'm no Javascript expert, but I'd imagine there has got to be a way to register a global on-error handler and post bug reports to the server? Any expert insight here?