Skip to content

Instantly share code, notes, and snippets.

@icodeforlove
Created May 11, 2012 02:06
Show Gist options
  • Save icodeforlove/2657066 to your computer and use it in GitHub Desktop.
Save icodeforlove/2657066 to your computer and use it in GitHub Desktop.
setTimeout + setInterval for non modern browsers
/**
* adds param support to older engines
*
* var timeoutID = window.setTimeout(func, delay, [param1, param2, ...]);
* var intervalID = window.setInterval(func, delay, [param1, param2, ...]);
*/
if (!Function.prototype.bind) (function () {
window.setTimeout = helper(window.setTimeout);
window.setInterval = helper(window.setInterval);
function helper (method) {
return function (func, timeout) {
var args = Array.prototype.slice.call(arguments, 2);
return method(function () {
func.apply(null, args);
}, timeout);
}
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment