Jquery Lingering objects

Source: Internet
Author: User

The deferred object, introduced in 1.5 in jquery, is a jQuery.Deferred() tool object that creates a chained invocation by invoking a method. It can register multiple callbacks to the callback queue, call the callback queue, and prepare to replace any synchronous or asynchronous function with a successful or failed state.

Deferred.alway ()

When the deferred (deferred) object is resolved or rejected, the add handler is called.

Deferred.always (Alwayscallbacks [, Alwayscallbacks])

Parameter alwayscallbacks type: A function or function array

Example:

1 function () {2   console.log ("$.get completed with success or error callback arguments"); 3 } ); 4 Object {readystate:1}5678 with success or error callback arguments

Deferred.done ()

When the deferred object is closed, the handler is added and the parameter is the same as Deferred.alway ()

Example:

1 functionB () {2Console.log ("Test");3 }4 5 6 varDtd=$.  Deferred (); Creating lingering Objects7 Dtd.resolve (); Changing lingering objects, delaying object resolution8Dtd.done (b). Done (function(){9Console.log ("B is done");Ten }); One  A Test -  -B is done

Deferred.fail ()

Called when a deferred object is rejected

1 var dtd = $. Deferred (); 2 Dtd.reject (); 3 dtd.fail (function() {Console.log ("fail")}); 4 5  Fail

Deferred.resolve ()

Set the lingering object to resolve and execute the callback function;

Deferred.reject ()

Denies lingering objects and executes callback functions;

Deferred.state ()

Determines the current state of a lingering object. This method does not accept parameters and returns only one string for the following three:

Resolved: Indicates that the lingering object is in the resolution state;

Rejected: Indicates that the deferred object is a deny state;

Pending: Indicates that lingering objects have not been resolved;

Deferrred.then ()

The add handler is called when the deferred (deferred) object is resolved, rejected, or still in progress.

Example:

1 functionA1 () {2             varDTD = $. Deferred (); 3Console.log ("AA");4 dtd.resolve ();5             6             returnDTD;7         }8 9 varan=A1 ();Ten  OneAn.then (function() { AConsole.log ("an"); -     }) -  the AA -  -An

Jquery Lingering objects

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.