加载中...

callbacks.fire()1.7+


概述    callbacks.fire( arguments )

返回值:Callbacks

描述:传入指定的参数调用所有的回调

  • V : 1.7callbacks.fire( arguments )

    • arguments
      类型: Anything
      这个参数或参数列表传回给回调列表。

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

示例

实例

使用 callbacks.fire() 用任何已传递的参数调用列表中的回调:

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

还没有评论.