返回值:undefinedcallbacks.fire(arguments)
调用所有的回调函数,并传入指定的参数。
-
1.7 新增callbacks.fire(arguments)
arguments () 将要传入到回调函数列表中的参数或参数列表。
示例
使用 callbacks.fire() 在回调函数列表中调用回调函数,并传入指定的参数:
// a sample logging function to be added to a callbacks list
var foo = function( value ){
console.log( 'foo:' + value );
}
var callbacks = $.Callbacks();
// add the function 'foo' to the list
callbacks.add( foo );
// fire the items on the list
callbacks.fire( 'hello' ); // outputs: 'foo: hello'
callbacks.fire( 'world '); // outputs: 'foo: world'
// add another function to the list
var bar = function( value ){
console.log( 'bar:' + value );
}
// add this function to the list
callbacks.add( bar );
// fire the items on the list again
callbacks.fire( 'hello again' );
// outputs:
// 'foo: hello again'
// 'bar: hello again'