Created
November 4, 2014 13:56
-
-
Save MoritzBuetzer/7affb8c4d649b9034c59 to your computer and use it in GitHub Desktop.
The 'quickEach' method will pass a non-unique jQuery instance to the callback meaning that there will be no need to instantiate a fresh jQuery instance on each iteration.
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
jQuery.fn.quickEach = (function(){ | |
var jq = jQuery([1]); | |
return function(c) { | |
var i = -1, el, len = this.length; | |
try { | |
while ( | |
++i < len && | |
(el = jq[0] = this[i]) && | |
c.call(jq, i, el) !== false | |
); | |
} catch(e){ | |
delete jq[0]; | |
throw e; | |
} | |
delete jq[0]; | |
return this; | |
}; | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment