返回值:undefinedcallbacks.fireWith([context], [args])
调用回调函数列表中的所有回调函数,并传入指定的上下文和参数。
-
1.7 新增callbacks.fireWith([context], [args])
context () 可选参数,指向在回调函数列表中,应该被调用的回调函数的上下文引用。args () 可选参数,向回调函数中传入的单个参数或参数数组。
示例
使用 callbacks.fireWith() 调用回调函数,并传入指定的上下文及一个参数数组:
// 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