callback回调问题(输出的结果为什么是这样)

来源:3-5 jQuery回调对象

shminyff

2015-05-28 16:24

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script src="http://img.mukewang.com/down/540812440001e40e00000000.js" type="text/javascript"></script>
<title></title>
</head>
<body>

<script type="text/javascript">

function show(data) {
  $("body").append('<li>' + data + '</li>')
}

function fn1(value) {
  show("fn1 says: "+value+'</br>');
}

function fn2(value) {
  fn1("fn2 says: " + value+'</br>');
  return false;
}
function fn3(value) {
  fn1("fn3 says: " + value+'</br>');
  return false;
}

var callbacks = $.Callbacks();

callbacks.add(fn1);
callbacks.fire("foo!");        //输出fn1 says:foo!
callbacks.add(fn2);
callbacks.fire("too!");    //输出 fn1 says:too!   fn1 says:fn2 says:too!
callbacks.add(fn3);
callbacks.fire("bar!");   //输出fn1 says:bar!   fn1 says:fn2 says:bar!    fn1 says:fn3 says:bar!

</script>

</body>
</html>

写回答 关注

1回答

  • shminyff
    2015-05-28 16:35:27

    sorry,各位,是我自己把方法调用写错了,浪费大家时间,非常抱歉

jQuery源码解析(架构与依赖模块)

由浅入深地剖析jQuery库的设计与实现,揭开框架背后的秘密

84047 学习 · 280 问题

查看课程

相似问题