2009-12-01 42 views
1
top.on('click', function(){ 
    anim.run(); 
}); 

我有一個動畫功能,並想知道爲什麼你要檢索,我不能在第二種情況下調用它YUI3調用函數

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

回答

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

top.on('click', Y.bind(anim.run, anim)); 
+0

謝謝,很高興看到YUI團隊成員! – Daniel 2009-12-02 20:59:19

3

因爲thisanimrun函數,而不是從anim調用它。

例如:

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

a.b() === 1; 
var bMethod = a.b; 
bMethod() === 2; 
+0

確定,所以top.on( '點擊',parent.anim.run);作品 謝謝 – Daniel 2009-12-01 04:57:51

+2

不,除非'run'沒有引用'this'。 – 2009-12-01 05:27:03