callbacks.has()

callbacks.has( [callback ] )返回类型:Boolean

描述:确定一个列表是否附加了回调函数。如果提供了一个回调函数作为参数,确定它是否在列表中。

示例:

使用callbacks.has()来检查某个回调函数列表是否包含了一个特定的回调函数:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// A sample logging function to be added to a callbacks list
var foo = function( value1, value2 ) {
console.log( "Received: " + value1 + "," + value2 );
};
// A second function which will not be added to the list
var bar = function( value1, value2 ) {
console.log( "foobar" );
};
var callbacks = $.Callbacks();
// Add the log method to the callbacks list
callbacks.add( foo );
// Determine which callbacks are in the list
console.log( callbacks.has( foo ) );
// true
console.log( callbacks.has( bar ) );
// false