I am trying to add my own error handling to the JavaScript setTimeout function. The following code works fine in chrome:
var oldSetTimeout = window.setTimeout;
window.setTimeout = function setTimeout(func, delay) {
var args = Array.prototype.slice.call(arguments, 0);
args[0] = function timeoutFunction() {
var timeoutArgs = Array.prototype.slice.call(arguments, 0);
try {
func.apply(this,timeoutArgs);
}
catch (exception) {
//Do Error Handling
}
}
return oldSetTimeout.apply(this, args);
}
But in IE7 it turns into a recursive function. For some reason oldSetTimeout
gets set to the new function.
Any suggestions?
side note: Yes, I need to do it this way. I am using a pile of 3rd party libraries all of which don't deal with setTimeout well, so I can't just change the calls to setTimeout.