如果我有这个javascript:
function I_did_something(){
this.test.assertExists('#selector', 'exists');
}
casper.then(I_did_something);问题是casper使用call来调用then方法,这意味着我不能做这样的事情:
@I_did_something = ->
@assertExists('#selector', 'exists')
casper.then @I_did_something因为this没有引用全局对象。
有没有人可以建议我如何在不使用window对象的情况下将其转换成coffeescript?
发布于 2012-08-09 01:43:25
可以使用fat arrow (=>)将函数绑定到当前this
@I_did_something = =>
@assertExists('#selector', 'exists')这具有类似的效果:
that = @
@I_did_something = ->
that.assertExists('#selector', 'exists')我想这就是你要找的。
https://stackoverflow.com/questions/11869288
复制相似问题