Created
May 13, 2010 17:38
-
-
Save paulirish/400118 to your computer and use it in GitHub Desktop.
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
// 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