Created
May 12, 2014 18:19
-
-
Save idettman/4cea50a6cb936636aa59 to your computer and use it in GitHub Desktop.
JS - Allow scope binding for timer and setInterval
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
/* JavaScript polyfill to fix scope issues with the setInterval */ | |
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