callbacks.fireWith()

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

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

  • 增补版本:1.7callbacks.fireWith( [context ] [, args ] )

    • context
      Type:
      对某上下文的引用,列表中的回调函数应该在该上下文中引发。
    • args
      Type:
      传递给列表中的回调函数的参数,或参数列表。

此方法把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"