Skip to content

Instantly share code, notes, and snippets.

@gnarf
Created May 2, 2011 19:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gnarf/952142 to your computer and use it in GitHub Desktop.
Save gnarf/952142 to your computer and use it in GitHub Desktop.
fn.promise() the way I saw it
// Get a promise resolved when the currently queued functions complete
promise: function( type ) {
type = type || "fx";
var defer = jQuery.Deferred(),
elements = this,
count = elements.length;
function resolve( next ) {
if ( !( --count ) ) {
defer.resolveWith( elements, [ elements ] );
}
next();
}
this.queue( type, resolve );
return defer.promise();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment