jquery Callback Object

Source: Internet
Author: User
Tags add object version

jquery provides developers with external interface calls, but $. The callbacks () module is developed to give internal $.ajax () and $. The Deferred () module provides a unified basic functional component. It can be used as a function of a new component defined in a similar basis.

jquery.callbacks is jQuery in the 1.7 version after the addition, is from the 1.6 version of the _deferred object, mainly used for function queue Add, remove, fire, lock and other operations, and provide once , memory, unique, stoponfalse four option for some special control.

The common scenario for this function is the event triggering mechanism, which is the publication and subscription mechanism of the observer pattern in the design pattern, and the current callbacks object is used in queue, Ajax, and deferred objects.

Ajax Modules

  1. Ajax:function (URL, options) {
  2. Omitting code
  3. deferred = Jquery.deferred (),
  4. completedeferred = Jquery.callbacks ("Once Memory")
  5. ..............
  6. }

It's not hard to find that Jquery.callbacks also provides parameters such as "Once Memory" for processing:

☑once: Make sure that this callback list executes only (. Fire ()) once (like a deferred Deferred).

☑memory: Keep the previous value and immediately execute the call to any callback (like a deferred Deferred) with the most recent value added to the list.

☑unique: Make sure you can only add one callback at a time (so there are no duplicate callbacks in the list).

☑stoponfalse: Interrupts the call when a callback returns false.

  1. var callbacks = $. Callbacks (' once ');
  2. Callbacks.add (function () {
  3. Alert (' a ');
  4. })
  5. Callbacks.add (function () {
  6. Alert (' B ');
  7. })
  8. Callbacks.fire (); Output result: ' A ' ' B '
  9. Callbacks.fire (); Not executed

The once function is to make the callback queue run only once.



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.