top.on('click', function(){
anim.run();
});
我有一个动画函数,想知道为什么我不能这样称呼它
top.on('click', anim.run);
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;