Created
May 2, 2011 19:00
-
-
Save gnarf/952142 to your computer and use it in GitHub Desktop.
fn.promise() the way I saw it
This file contains hidden or 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
// 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