Created
December 6, 2014 23:28
-
-
Save matthewmorrone/69ab7a7af10aa97cb9e3 to your computer and use it in GitHub Desktop.
I always forget the order of arguments for setInterval and setTimeout
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
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); | |
// }; |
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
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