override - overriding a global function in javascript -



override - overriding a global function in javascript -

i trying add together own error handling javascript settimeout function. next 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); seek { func.apply(this,timeoutargs); } grab (exception) { //do error handling } } homecoming oldsettimeout.apply(this, args); }

but in ie7 turns recursive function. reason oldsettimeout gets set new function.

any suggestions?

side note: yes, need way. using pile of 3rd party libraries of don't deal settimeout well, can't alter calls settimeout.

this because you're using named function expressions, incorrectly implemented in ie. removing function names prepare immediate problem. see kangax's excellent article on subject. however, there's problem isn't fixed.

in general, it's not thought effort override properties of host objects (such window, document or dom element), because there's no guarantee environment allow it. host objects not bound same rules native objects , in essence can like. there's no guarantee host method function object, , hence oldsettimeout may not have have apply() method. case in ie, phone call oldsettimeout.apply(this, args); not work.

i'd suggest next instead:

window.oldsettimeout = window.settimeout; window.settimeout = function(func, delay) { homecoming window.oldsettimeout(function() { seek { func(); } grab (exception) { //do error handling } }, delay); };

javascript override global settimeout

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -