Created
May 13, 2011 12:47
-
-
Save Boldewyn/970473 to your computer and use it in GitHub Desktop.
jQuery deferring helper
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
var $=(function(){var x=[],z=setInterval(function(){if("jQuery" in window){$.each(x,function(){$(this)});clearInterval(z)}},10);return function(y){x.push(y)}})(); | |
/* uncompressed: */ | |
var $ = (function() { | |
var x = [], | |
z = setInterval(function() { | |
if ("jQuery" in window) { | |
$.each(x, function() { | |
$(this); | |
}); | |
clearInterval(z); | |
} | |
}, 10); | |
return function (y) { | |
x.push(y); | |
}; | |
})(); |
By the way, quite the same solution in an 2008 jQuery list posting:
http://groups.google.com/group/jquery-en/browse_thread/thread/f31d8cf3ec8cd55a
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If you use
defer="defer"
on jQuery, the$
variable isn't defined, until jQuery has loaded. To be able to embed$(function(){})
-style code though, this little helper (162B) will take care of defining a fallback$
until this happens.