Skip to content

Instantly share code, notes, and snippets.

@paulirish
Created May 13, 2010 17:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paulirish/400118 to your computer and use it in GitHub Desktop.
Save paulirish/400118 to your computer and use it in GitHub Desktop.
// fixing The Mysterious Firefox setTimeout "Lateness" argument™
// by paul irish
// detail: http://benalman.com/news/2009/07/the-mysterious-firefox-settime/
// "feature" test
void setTimeout(function(){
if (arguments.length==1){ // bad mozilla!, bad!
// now, we fix
(function(){
var old = window.setTimeout;
window.setTimeout = function(func,delay){
var args = Array.prototype.slice.call(arguments,2,arguments.length);
return old.call(window,function(){
func.apply(window,Array.prototype.slice.call(args));
},delay);
}
})();
}
},0)
// Does it work?
// because the feature test is asynchronous, this will probably fail
// if immediately executed afterwards.
// if you sniffed for firefox/gecko instead of feature testing, this
// would be synchronous and this test would immediately pass
setTimeout(function(){
console.log('is setTimeout normalized now?',arguments.length==3);
},4,'true',false,5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment