加载中...

callbacks.add()1.7+


概述    callbacks.add( callbacks )

返回值:Callbacks

描述:回调列表中添加一个回调或回调的集合。

  • V : 1.7callbacks.add( callbacks )

    • callbacks
      类型: Function, Array
      一个函数,或者一个函数数组,用来添加到回调列表。

此方法返回绑定它的那个回调对象(this).

示例

使用 callbacks.add() 添加新的回调到回调列表:

  1. // a sample logging function to be added to a callbacks list
  2. var foo = function( value ) {
  3. console.log( "foo: " + value );
  4. };
  5. // another function to also be added to the list
  6. var bar = function( value ){
  7. console.log( "bar: " + value );
  8. };
  9. var callbacks = $.Callbacks();
  10. // add the function "foo" to the list
  11. callbacks.add( foo );
  12. // fire the items on the list
  13. callbacks.fire( "hello" );
  14. // outputs: "foo: hello"
  15. // add the function "bar" to the list
  16. callbacks.add( bar );
  17. // fire the items on the list again
  18. callbacks.fire( "world" );
  19. // outputs:
  20. // "foo: world"
  21. // "bar: world"


还没有评论.