Skip to content

Instantly share code, notes, and snippets.

@tantalor
Created December 1, 2009 17:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tantalor/246484 to your computer and use it in GitHub Desktop.
Save tantalor/246484 to your computer and use it in GitHub Desktop.
// John Tantalo
jQuery.fn.chain = function (fn)
{
var self = this;
return function ()
{
if (!self.size()) return;
fn(self.eq(0), self.slice(1).chain(fn));
}
}
// example
jQuery("foo").click(jQuery("bar").chain(fn));
function fn(element, callback)
{
// some crap with element
if (callback) callback();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment