Skip to content

Instantly share code, notes, and snippets.

@matthewmorrone
Created December 6, 2014 23:28
Show Gist options
  • Save matthewmorrone/69ab7a7af10aa97cb9e3 to your computer and use it in GitHub Desktop.
Save matthewmorrone/69ab7a7af10aa97cb9e3 to your computer and use it in GitHub Desktop.
I always forget the order of arguments for setInterval and setTimeout
if (window.nativeSetInterval) {
window.setInterval = window.nativeSetInterval;
delete window.nativeSetInterval;
}
// requires object.define.js, arguments.js, array.swap.js, log.js
window.define("nativeSetInterval", setInterval);
window.define("setInterval", function() {
if (typeof arguments[0] === "number") {
arguments.swap(0, 1);
}
return nativeSetInterval(arguments[0], arguments[1]);
});
// var inter1 = setInterval(1000, function() {log("done");});
// var inter2 = setInterval(function() {log("done");}, 1000);
// this should work by itself
// window.nativeSetInterval = window.setInterval;
// window.setInterval = function(func, delay) {
// if (typeof arguments[0] === "number") {
// var tmp = func;
// func = delay;
// delay = tmp;
// }
// return window.nativeSetInterval(function() {
// try {func();}
// catch (e) {}
// }, delay);
// };
if (window.nativeSetTimeout) {
window.setTimeout = window.nativeSetTimeout;
delete window.nativeSetTimeout;
}
// requires object.define.js, arguments.js, array.swap.js, log.js
window.define("nativeSetTimeout", setTimeout);
window.define("setTimeout", function() {
if (typeof arguments[0] === "number") {
arguments.swap(0, 1);
}
return nativeSetTimeout(arguments[0], arguments[1]);
});
// setTimeout(1000, function() {log("done");});
// setTimeout(function() {log("done");}, 1000);
// this should work by itself
// window.nativeSetTimeout = window.setTimeout;
// window.setTimeout = function(func, delay) {
// if (typeof arguments[0] === "number") {
// var tmp = func;
// func = delay;
// delay = tmp;
// }
// return window.nativeSetTimeout(function() {
// try {func();}
// catch (e) {}
// }, delay);
// };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment