Using groovy , you can run closure like following :
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();
}
}
As you may note, we call directly methodA
inside closure without this
(this.methodA()
) .
This is because of this instruction c.delegate=new A()
: Therefore, All methods of new A()
can be called there .
My question :
How to make this works with Javascript using Arrow-functions : Either ES6 or ES7 .
Does Arrow-functions has something like delegate
?
Pseudo code :
instanceB.methodB(()=>{
methodA(3);
methodA(4);
});
class B{
methodB(arrow){
arrow.delegate=new A(); // What's the right way, if any ?
arrow.call();
}
}