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.
This commit is contained in:
parent
c272f5f7da
commit
5798446b98
1 changed files with 9 additions and 4 deletions
13
src/core.js
13
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue