Skip to content

Instantly share code, notes, and snippets.

@MoritzBuetzer
Created November 4, 2014 13:56
Show Gist options
  • Save MoritzBuetzer/7affb8c4d649b9034c59 to your computer and use it in GitHub Desktop.
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.
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