substituindo uma função global em javascript
Estou tentando adicionar meu próprio tratamento de erros à função setTimeout do JavaScript. O código a seguir funciona bem no 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);
}
Mas no IE7, ele se transforma em uma função recursiva. Por algum motivooldSetTimeout
é definido para a nova função.
Alguma sugestão?