题
top.on('click', function(){
anim.run();
});
我有一个动画功能,并想知道为什么不能这样称呼它
top.on('click', anim.run);
解决方案
top.on('click', function () { anim.run(); });
或
top.on('click', Y.bind(anim.run, anim));
其他提示
由于作为你检索this
功能,而不是从anim
调用它run
未在第二种情况下anim
。
例如:
var a = {
b: function () {
return this.c;
},
c: 1
},
c = 2;
a.b() === 1;
var bMethod = a.b;
bMethod() === 2;
不隶属于 StackOverflow