Categories

callbacks.fireWith()

Categories: Callbacks Object

callbacks.fireWith( [ context ], [ args ] )Returns: undefined

Description: Call all callbacks in a list with the given context and arguments.

  • callbacks.fireWith( [ context ], [ args ] )

    version added: 1.1

    context   A reference to the context in which the callbacks in the list should be fired.

    args   An argument, or array of arguments, to pass to the callbacks in the list.

Example

Using callbacks.fireWith() to fire a list of callbacks with a specific context and an array of arguments:

// a sample logging function to be added to a callbacks list
var log = function( value1, value2 ){
    console.log( 'Received:' + value1 + ',' + value2 );
}

var callbacks = $.Callbacks();

// add the log method to the callbacks list
callbacks.add( log );

// fire the callbacks on the list using the context 'window'
// and an arguments array

callbacks.fireWith( window, ['foo','bar']);

// outputs: Received: foo, bar