callbacks.fireWith() JQ Home  <<  Objects  <<  callbacks.fireWith()

Invoke the callbacks list within a context.

Description

The callbacks.fireWith() Callbacks object method, allows us to invoke the callback list with the specified context and arguments.

Syntax

Signature Description
callbacks.fireWith( context, [arguments] )Invoke the callback list with the specified context and arguments.

Parameters

Parameter Description Type
contextThe context in which the callbacks in the list should be fired.String
argumentsAn array of arguments to pass back to the callback list.Array

Return

undefined.

callbacks.fireWith( context, [arguments] ) Example Objects  <<  Top

Invoke the callback list with the specified context and arguments.

In the example below when we press the button the first time we add the aFunc(value, div) and bFunc(value, div) functions to our callbacks list and fire them off with a context and array of arguments.


$(function(){
  $('#btn14').one('click', function(){
    var ourCallbacks = $.Callbacks();
    ourCallbacks.add( aFunc );
    ourCallbacks.add( bFunc );
    ourCallbacks.fireWith( window, ['Callbacks list called from the callbacks.fireWith()
                                     method. <br>','#div14']);
  });
  function aFunc( value, div ){
    $(div).append( value);
  }
  function bFunc( value, div ){
    aFunc('Passing bFunc function value to aFunc. <br>', div);
  }
});

div14. Some initial text.

Press the button below to action the above code:

Related Tutorials

jQuery Advanced Tutorials - Lesson 6 - The Callbacks Object