2012-08-08 62 views
1

如果我有这样的javascript:CoffeeScript的翻译

function I_did_something(){ 
    this.test.assertExists('#selector', 'exists'); 
} 

casper.then(I_did_something); 

的问题是,卡斯帕使用call调用then方法意味着我不能做这样的事情:

@I_did_something = -> 
    @assertExists('#selector', 'exists') 

casper.then @I_did_something 

因为this做不是指全局对象。

任何人都可以建议如何将其转换为咖啡脚本而不使用窗口对象吗?

回答

0

您可以使用fat arrow (=>)的功能绑定到当前this

@I_did_something = => 
    @assertExists('#selector', 'exists') 

具有类似的效果:

,我想这就是你以后。