jQuery callbacks.lock()Method

jQuery 杂项方法jQuery Miscellaneous Methods

Example

Use callbacks.lock() to lock a callback list to avoid further modification of the list state

$(function () { //A simple function that will be added to the list var foo = function( value ) { alert( "foo: " + value ); }; var callbacks = $.Callbacks(); //Add the function to the list callbacks.add( foo ); //Call all callbacks in the list with the given arguments callbacks.fire( "hello" ); //Output "foo: hello" //Lock the callback list callbacks.lock(); //Try to call the callback list again callbacks.fire( "world" ); //When the list is locked, no items can be called, so "world" will not be passed in and executed })

Try it yourself »

Definition and Usage

The callbacks.lock() function is used to lock the callback list in its current state.

Note:1. If the callback object is created with the "memory" flag as its parameter, bound functions may be added and fired after the callback list is locked.
2. This method returns a callback object to the callback list it is bound to.


Syntax

This method does not accept any parameters.

callbacks.lock()


实例

More Examples

Create a callback object using "memory" as the parameter
Create a callback object using "memory" as the parameter, then view the list.


jQuery 杂项方法jQuery Miscellaneous Methods

Other Extensions