使用Groovy,你可以像下面运行关闭:不Arrow功能具有委职能属性如Groovy封闭
instanceB.methodB({
methodA(3);
methodA(3);
});
//---- methodB definition
class B{
def methodB(Closure c){
c.delegate=new A(); //!!!---The question is about this "delegate" in JS
c.call();
}
}
正如您可能注意到,我们称之为直接methodA
内封闭无this
(this.methodA()
)。 这是因为这个指令c.delegate=new A()
:因此,在那里可以调用new A()
的所有方法。
我的问题:
如何使这种使用箭功能的工作原理使用Javascript:要么ES6或ES7。
箭头函数是否有类似delegate
?
伪代码:
instanceB.methodB(()=>{
methodA(3);
methodA(4);
});
class B{
methodB(arrow){
arrow.delegate=new A(); // What's the right way, if any ?
arrow.call();
}
}
有没有更新?没有人知道Groovy&JS –
我不知道这与箭头函数有什么关系。 JS中没有特别的范围。 – Bergi
你可能想看看http://stackoverflow.com/q/21562973/1048572 – Bergi