Last active
August 29, 2015 14:23
-
-
Save casecode/3ad35d1f454b7787a710 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
var poll = function (sel, fn, t) { | |
t = t || 25; // 25ms default | |
var $el = $(sel), found = $el.length; | |
// Proper tail calls - return and pass all necessary variables | |
// i.e. minimize current frame's footprint (allow release / reuse in es6 env) | |
if (found) return fn.call($el); | |
else if (document.readyState === 'complete') return; | |
else return setTimeout(function() { | |
poll(sel, fn, t); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment