Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use the callbacks.lock () method

Shulou Source: shulou.com Published: 2022-06-01 07:34:35 10月02日 Update

This article will explain in detail how to use the callbacks.lock () method. The editor thinks it is very practical, so I share it for you as a reference. I hope you can get something after reading this article.

Callbacks.lock ()

Description: locks the current state of the callback list.

Added version: 1.7callbacks.lock ()

This method does not accept any parameters

This method returns the callback object (this) that binds it.

If the callback object is created, using the "memory" flag as its parameter, the binding function may be added and triggered after it is locked in the callback list.

Example:

Example: lock a callback list with callbacks.lock () to avoid further changes to the list status:

/ / a sample logging function to be added to a callbacks list

Var foo = function (value) {

Console.log ("foo:" + value)

}

Var callbacks = $.Callrooms ()

/ / add the logging function to the callback list

Callbacks.add (foo)

/ / fire the items on the list, passing an argument

Callbacks.fire ("hello")

/ / outputs "foo: hello"

/ / lock the callbacks list

Callbacks.lock ()

/ / try firing the items again

Callbacks.fire ("world")

/ / as the list was locked, no items

/ / were called, so "world" isn "t logged

Example: Use callbacks.lock () to lock a callback list with "memory," and then resume using the list:

/ / simple function for logging results

Var log = function (value) {

("# log") .append ("

"+ value +"

")

}

/ / two sample functions to be added to a callbacks list

Var foo = function (value) {

Log ("foo:" + value)

}

Var bar = function (value) {

Log ("bar:" + value)

}

/ / create the callbacks object with the "memory" flag

Var callbacks = $.Callboxes ("memory")

/ / add the foo logging function to the callback list

Callbacks.add (foo)

/ / fire the items on the list, passing an argument

Callbacks.fire ("hello")

/ / outputs "foo: hello"

/ / lock the callbacks list

Callbacks.lock ()

/ / try firing the items again

Callbacks.fire ("world")

/ / as the list was locked, no items were called

/ / so "foo: world" isn't logged

/ / add the foo function to the callback list again

Callbacks.add (foo)

/ / try firing the items again

Callbacks.fire ("silentArgument")

/ / outputs "foo: hello" because the argument value was stored in memory

/ / add the bar function to the callback list

Callbacks.add (bar)

Callbacks.fire ("youHadMeAtHello")

/ / outputs "bar: hello" because the list is still locked

/ / and the argument value is still stored in memory

This is the end of the article on "how to use the callbacks.lock () method". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.

Tags: Methods articles parameters objects more states good practical examples content functions articles flags this method version knowledge enter one reference help related Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Tech Info Huawei vpn MariaDB Shulou Technology