Commit 5798446b authored by jaubourg's avatar jaubourg

Put the split to get the list of promise methods out of the promise method...

Put the split to get the list of promise methods out of the promise method 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.
parent c272f5f7
...@@ -63,6 +63,9 @@ var jQuery = function( selector, context ) { ...@@ -63,6 +63,9 @@ var jQuery = function( selector, context ) {
// The deferred used on DOM ready // The deferred used on DOM ready
readyList, readyList,
// Promise methods
promiseMethods = "then done fail isResolved isRejected promise".split( " " ),
// The ready event handler // The ready event handler
DOMContentLoaded, DOMContentLoaded,
...@@ -914,16 +917,18 @@ jQuery.extend({ ...@@ -914,16 +917,18 @@ jQuery.extend({
isRejected: failDeferred.isResolved, isRejected: failDeferred.isResolved,
// Get a promise for this deferred // Get a promise for this deferred
// If obj is provided, the promise aspect is added to the object // 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 ( obj == null ) {
if ( promise ) { if ( promise ) {
return promise; return promise;
} }
promise = obj = {}; promise = obj = {};
} }
jQuery.each( "then done fail isResolved isRejected promise".split( " " ) , function( _ , method ) { i = promiseMethods.length;
obj[ method ] = deferred[ method ]; while( i-- ) {
}); obj[ promiseMethods[ i ] ] = deferred[ promiseMethods[ i ] ];
}
return obj; return obj;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment