callbacks.locked()
JQ Home <<
Objects <<
callbacks.locked()
Locked callbacks list state.
Description
The callbacks.locked()
Callbacks object method, allows us to determine whether the callback list is in a locked state.
Syntax
Signature | Description |
---|---|
callbacks.locked() | Determine whether the callback list is in a locked state. |
Parameters
None.
Return
A Boolean
object.
callbacks.locked()
Example
Objects << Top
Determine whether the callback list is in a locked state.
In the example below when we press the button the first time we add the aFunc(value, div)
function to our callbacks list and then fire the list off. We then check to see if the callbacks list has been
locked using the callbacks.locked()
method, which returns false
. After this we lock the list and then try to add and fire the bFunc(value, div)
function. Because the callback
list is now locked nothing happens. We then check to see if the callbacks list has been locked using the callbacks.locked()
method, which now returns true
.
$(function(){
$('#btn12').one('click', function(){
var ourCallbacks = $.Callbacks();
ourCallbacks.add( aFunc );
ourCallbacks.fire( 'The aFunc
function was fired from our callbacks. <br>', '#div12');
$('#div12').append( 'Has callbacks list been locked? ' + ourCallbacks.locked() + '<br>');
ourCallbacks.lock();
ourCallbacks.add( bFunc );
ourCallbacks.fire( 'The bFunc
function was fired from our callbacks. <br>', '#div12');
$('#div12').append( 'Has callbacks list been locked? ' + ourCallbacks.locked() + '<br>');
});
function aFunc( value, div ){
$(div).append( value);
}
function bFunc( value, div ){
aFunc('Passing bFunc
function value to aFunc
. <br>', div);
}
});
div12. Some initial text.
Related Tutorials
jQuery Advanced Tutorials - Lesson 6 - The Callbacks Object