callbacks.fireWith()

callbacks.fireWith()

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

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

  • version added: 1.7callbacks.fireWith( [context ] [, args ] )

    • context
      Type:
      A reference to the context in which the callbacks in the list should be fired.
    • args
      Type:
      An argument, or array of arguments, to pass to the callbacks in the list.

This method returns the Callbacks object onto which it is attached (this).

Example:

Use 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"

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jquery.com/callbacks.fireWith

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部