Wednesday, March 21, 2012

Overriding core JavaScript methods for debugging, fun, profit

Hallvord Steen's epic tale of debugging a Google Maps bug is essential reading for anyone dealing with JS on a daily basis. It's full of useful techniques to adapt and use.

What I especially like is his trick for catching bugs associated with core JavaScript functions, when you don't know how the code is called: just redefine the function to something that doesn't work.


javascript:void(Element.prototype.removeChild=function(){undefined()})

When the script needs to call removeChild it uses the overridden function and (because undefined() doesn't really exist) throws a handy stack trace into the console so you can see where the problem occurs. 

No comments:

Post a Comment