callbacks.lock()S2C Home « Objects « callbacks.lock()

Lock a callbacks list.

Description

The callbacks.lock() Callbacks object method, locks a callback list.

Syntax


Signature Description
callbacks.lock()Lock a callback list.

Parameters

None.

Return

undefined.

callbacks.lock() Examplego to top of page Top

Lock a callback list.

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. 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.


$(function(){
  $('#btn11').one('click', function(){
    var ourCallbacks = $.Callbacks();
    ourCallbacks.add( aFunc );
    ourCallbacks.fire( 'The aFunc function was fired from our callbacks. <br />', '#div11');
    ourCallbacks.lock();
    ourCallbacks.add( bFunc );
    ourCallbacks.fire( 'The bFunc function was fired from our callbacks. <br />', '#div11');
  });
  function aFunc( value, div ){
    $(div).append( value);
  }
  function bFunc( value, div ){
    aFunc('Passing bFunc function value to aFunc. <br />', div);
  }
});

div11. Some initial text.

Press the button below to action the above code:



go to home page Homepage go to top of page Top