jquery's Callback Object

Source: Internet
Author: User

1. The new function in the JQuery 1.7 release jQuery.Callbacks() returns an all-purpose object that provides a powerful way to manage the callback list. It can add, delete, trigger, and disable callback functions.

2. Callbacks.add () Method: Adds a callback or callback collection to the callback list. The following code:

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "UTF-8">        <title></title>        <Scripttype= "Text/javascript"src= "Js/jquery-3.1.1.min.js" ></Script>    </Head>    <Body>            </Body>        <Scripttype= "Text/javascript">        $(function(){            vartest1= function(value) {Console.info (value+"test1"); }                        vartest2= function(value) {Console.info (value+"test2"); }                        varCallbacks= $.                        Callbacks (); //Add Method Test1Callbacks.add (test1); //Add Method Test2Callbacks.add (test2); //pass in the specified parameter and invoke all callbacks, which must be taken with parameters, otherwise it will be displayed undefinedCallbacks.fire ("this is"); Callbacks.fire ("");        Callbacks.fire ();    }); </Script></HTML>

Code effects Show:

3. Callbacks.disable () Method: Disables callbacks in the callback list, disables the use of the Callbacks.fire () method and does not result in output.

4. Callbacks.disabled () Method: Verify that the callback list is disabled. This can return a Boolean value that returns true if disabled, otherwise false.

5. Callbacks.empty () Method: Removes all callbacks from the callback list. The callback that was added earlier is gone.

6. Callbacks.fire () Method: Pass in the specified parameter and invoke all callbacks. Here is an example of the above.

7. Callbacks.firewith ([context] [, args]) method: Accesses all callbacks in the given context and argument list. If the method has more than one parameter, the callback that has fewer arguments than those parameters will get the value of the parameter from the back.

<!DOCTYPE HTML><HTML>    <Head>        <MetaCharSet= "UTF-8">        <title></title>        <Scripttype= "Text/javascript"src= "Js/jquery-3.1.1.min.js" ></Script>    </Head>    <Body>            </Body>        <Scripttype= "Text/javascript">        $(function(){            vartest1= function(value1,value2) {console.info (value1+value2+"test1"); }                        vartest2= function(value) {Console.info (value+"test2"); }                        varCallbacks= $.                        Callbacks (); //Add Method Test1Callbacks.add (test1); //Add Method Test2Callbacks.add (test2); Callbacks.firewith (window,["this","is that"]);    }); </Script></HTML>

8. Callbacks.fired () Method: Verify that the callback has been called at least once. If it is called at least once, it returns true, otherwise it returns false.

9. Callbacks.has () Method: Verify that a callback is provided in the callback list.

Callbacks.lock () Method: Locks the current state of the callback list.

Callbacks.locked () Method: Determines whether the callback list is locked.

Callbacks.remove () Method: Removes a callback or callback collection from the callback list.

Jquery.callbacks () Method: A Multipurpose callback list object that provides a powerful way to manage the list of callback functions.

jquery's Callback Object

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.