Easy Tutorial
❮ Misc Browser Misc Inarray ❯

jQuery callbacks.lock() Method

jQuery Miscellaneous Methods

Example

Lock a callback list using callbacks.lock() to prevent further modifications to the list state.

$(function () { 
    // A simple function to 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 argument "hello"
    callbacks.fire( "hello" );
    // Outputs "foo: hello"    
    // Lock the callback list
    callbacks.lock();
    // Attempt 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 to execute

})

Definition and Usage

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

Note: 1. If the callback object is created with the "memory" flag as its argument, bound functions may be added and triggered even after the callback list is locked.


Syntax

This method does not accept any parameters.


More Examples

Creating a callback object with "memory" as an argument


jQuery Miscellaneous Methods

❮ Misc Browser Misc Inarray ❯