top.on('click', function(){
anim.run();
});
我有一個動畫功能,並想知道爲什麼你要檢索,我不能在第二種情況下調用它YUI3調用函數
top.on('click', anim.run);
top.on('click', function(){
anim.run();
});
我有一個動畫功能,並想知道爲什麼你要檢索,我不能在第二種情況下調用它YUI3調用函數
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;
確定,所以top.on( '點擊',parent.anim.run);作品 謝謝 – Daniel 2009-12-01 04:57:51
不,除非'run'沒有引用'this'。 – 2009-12-01 05:27:03
謝謝,很高興看到YUI團隊成員! – Daniel 2009-12-02 20:59:19