callbacks.fireWith()


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

描述: 使用给定的上下文和参数调用列表中的所有回调函数。

此方法返回附加到它的 Callbacks 对象 (this)。

示例

使用 callbacks.fireWith() 来使用特定上下文和参数数组触发回调函数列表

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// 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"