Skip to content

Commit

Permalink
Put the split to get the list of promise methods out of the promise m…
Browse files Browse the repository at this point in the history
…ethod itself and also switched from jQuery.each to a while loop to remove as much overhead as possible. Thanks go to scott_gonzalez for reminding me of this.
  • Loading branch information
jaubourg committed Jan 16, 2011
1 parent c272f5f commit 5798446
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/core.js
Expand Up @@ -63,6 +63,9 @@ var jQuery = function( selector, context ) {
// The deferred used on DOM ready
readyList,

// Promise methods
promiseMethods = "then done fail isResolved isRejected promise".split( " " ),

// The ready event handler
DOMContentLoaded,

Expand Down Expand Up @@ -914,16 +917,18 @@ jQuery.extend({
isRejected: failDeferred.isResolved,
// Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object
promise: function( obj ) {
// (i is used internally)
promise: function( obj , i ) {
if ( obj == null ) {
if ( promise ) {
return promise;
}
promise = obj = {};
}
jQuery.each( "then done fail isResolved isRejected promise".split( " " ) , function( _ , method ) {
obj[ method ] = deferred[ method ];
});
i = promiseMethods.length;
while( i-- ) {
obj[ promiseMethods[ i ] ] = deferred[ promiseMethods[ i ] ];
}
return obj;
}

Expand Down

0 comments on commit 5798446

Please sign in to comment.