mirror of
https://github.com/jquery/jquery.git
synced 2024-11-23 02:54:22 +00:00
Removed custom method in isDeferred and when.
This commit is contained in:
parent
846c52d1f8
commit
5237b09602
13
src/core.js
13
src/core.js
@ -936,20 +936,15 @@ jQuery.extend({
|
||||
},
|
||||
|
||||
// Check if an object is a deferred
|
||||
isDeferred: function( object , method ) {
|
||||
method = method || "then";
|
||||
return !!( object && object[ method ] && object[ method ]._ === deferredMarker );
|
||||
isDeferred: function( object ) {
|
||||
return !!( object && object.then && object.then._ === deferredMarker );
|
||||
},
|
||||
|
||||
// Deferred helper
|
||||
when: function( object , method ) {
|
||||
method = method || "then";
|
||||
object = jQuery.isDeferred( object , method ) ?
|
||||
when: function( object ) {
|
||||
object = jQuery.isDeferred( object ) ?
|
||||
object :
|
||||
jQuery.Deferred().resolve( object );
|
||||
object.fail = object.fail || function() { return this; };
|
||||
object[ method ] = object[ method ] || object.then;
|
||||
object.then = object.then || object[ method ];
|
||||
return object;
|
||||
},
|
||||
|
||||
|
@ -1022,7 +1022,7 @@ test("jQuery.Deferred()", function() {
|
||||
|
||||
test("jQuery.isDeferred()", function() {
|
||||
|
||||
expect( 11 );
|
||||
expect( 10 );
|
||||
|
||||
var object1 = { then: function() { return this; } },
|
||||
object2 = { then: function() { return this; } };
|
||||
@ -1047,14 +1047,13 @@ test("jQuery.isDeferred()", function() {
|
||||
object1 = {custom: jQuery._Deferred().then};
|
||||
|
||||
ok(!jQuery.isDeferred(object1) , "custom method name not found automagically");
|
||||
ok(jQuery.isDeferred(object1,"custom") , "custom method name");
|
||||
});
|
||||
|
||||
test("jQuery.when()", function() {
|
||||
|
||||
expect( 5 );
|
||||
expect( 2 );
|
||||
|
||||
var cache, i, deferred = { done: jQuery.Deferred().resolve( 1 ).then };
|
||||
var cache, i;
|
||||
|
||||
for( i = 1 ; i < 3 ; i++ ) {
|
||||
jQuery.when( cache || jQuery.Deferred( function() {
|
||||
@ -1066,22 +1065,4 @@ test("jQuery.when()", function() {
|
||||
ok( false , "Fail called" );
|
||||
});
|
||||
}
|
||||
|
||||
cache = 0;
|
||||
|
||||
for( i = 1 ; i < 3 ; i++ ) {
|
||||
jQuery.when( cache || deferred , "done" ).done( function( value ) {
|
||||
strictEqual( value , 1 , "Custom method: resolved" + ( i > 1 ? " only once" : "" ) );
|
||||
cache = value;
|
||||
}).fail( function() {
|
||||
ok( false , "Custom method: fail called" );
|
||||
});
|
||||
}
|
||||
|
||||
stop();
|
||||
|
||||
jQuery.when( jQuery( document ) , "ready" ).then( function( test ) {
|
||||
strictEqual( test , jQuery , "jQuery.fn.ready recognized as a deferred" );
|
||||
start();
|
||||
});
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user