Created
January 22, 2014 10:29
-
-
Save Bartunek/8556564 to your computer and use it in GitHub Desktop.
Native timers extended for passage of 'this' object
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Enable the passage of the 'this' object through the JavaScript timers | |
* | |
**/ | |
var __nativeST__ = window.setTimeout, __nativeSI__ = window.setInterval; | |
window.setTimeout = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) { | |
var oThis = this, aArgs = Array.prototype.slice.call(arguments, 2); | |
return __nativeST__(vCallback instanceof Function ? function () { | |
vCallback.apply(oThis, aArgs); | |
} : vCallback, nDelay); | |
}; | |
window.setInterval = function (vCallback, nDelay /*, argumentToPass1, argumentToPass2, etc. */) { | |
var oThis = this, aArgs = Array.prototype.slice.call(arguments, 2); | |
return __nativeSI__(vCallback instanceof Function ? function () { | |
vCallback.apply(oThis, aArgs); | |
} : vCallback, nDelay); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment