1
top.on('click', function(){
    anim.run();
});

我有一个动画函数,想知道为什么我不能这样称呼它

top.on('click', anim.run);
4

2 回答 2

4
top.on('click', function () { anim.run(); });

或者

top.on('click', Y.bind(anim.run, anim));
于 2009-12-01T22:16:51.040 回答
3

因为this不是anim第二种情况,因为您正在检索run函数而不是从anim.

例如:

var a = {
  b: function () {
    return this.c;
  },
  c: 1
},
c = 2;

a.b() === 1;
var bMethod = a.b;
bMethod() === 2;
于 2009-12-01T04:45:16.110 回答