Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use jQuery.Callbacks ()

Shulou Source: shulou.com Published: 2022-06-01 07:34:53 09月28日 Update

This article mainly introduces how to use jQuery.Callbacks (), has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.

JQuery.Callbacks (flags)

Description: a multi-purpose callback list object that provides a powerful way to manage callback function lists.

Added version: 1.7jQuery.Callbacks (flags)

Flags

Type: String

An optional list of flags separated by space tags to change the behavior in the callback list.

The $.ajax () and $.Deferred () basic functional components of jQuery are provided inside $. Callable (). It can be used as a function of a new component similar to the basic definition.

Methods supported by $. Callers (), including callbacks.add (), callbacks.remove (), callbacks.fire () and callbacks.disable ().

Getting started (getting started)

Here are two sample methods named fn1 and fn2:

Function fn1 (value) {

Console.log (value)

}

Function fn2 (value) {

Fn1 ("fn2 says:" + value)

Return false

}

These can be added as callback functions as a list of $.Callbacks and called as follows:

Var callbacks = $.Callrooms ()

Callbacks.add (fn1)

/ / outputs: foo!

Callbacks.fire ("foo!")

Callbacks.add (fn2)

/ / outputs: bar!, fn2 says: bar!

Callbacks.fire ("bar!")

As a result, it makes it easy to construct a complex list of callbacks, and the input values can be easily used as needed by as many functions as possible.

The above two specific methods: .add () and .fire () .add () support adding new callback lists, while .fire () provides a way to handle callback methods in the same list.

The other method, by .remove () of $.Callbacks, removes a specific callback from the callback list. Here is an example of the use of .remove ():

Var callbacks = $.Callrooms ()

Callbacks.add (fn1)

/ / outputs: foo!

Callbacks.fire ("foo!")

Callbacks.add (fn2)

/ / outputs: bar!, fn2 says: bar!

Callbacks.fire ("bar!")

Callbacks.remove (fn2)

/ / only outputs foobar, as fn2 has been removed.

Callbacks.fire ("foobar")

Supported Flags (supported Flags)

This flags parameter is an optional parameter for $. Callbacks () and is structured as an optional list of flags separated by space tags to change the behavior in the callback list (for example. $.Callflower ('unique stopOnFalse')).

Thank you for reading this article carefully. I hope the article "how to use jQuery.Callbacks ()" shared by the editor will be helpful to everyone. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!

Tags: Methods articles support functions two functions parameters flags tags spaces components behaviors complex powerful value examples interests can be passed at the same time the foundation Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Linux Microsoft Redmi Docker vpn