Skip to content
Permalink
Browse files

Put the split to get the list of promise methods out of the promise m…

…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 5798446b9816daca48e8c03791f4afc0ab0ac4cf
Showing with 9 additions and 4 deletions.
  1. +9 −4 src/core.js
@@ -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,

@@ -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;
}

0 comments on commit 5798446

Please sign in to comment.
You can’t perform that action at this time.