Impossible to get the this
of caller function | Constructor.
It seems : NodeJS , Client-Side(Firefox,....) are avoid arguments.callee.caller
with ES6 ,
Any solution to this problem ,known that ,
my ES5 code is : ✓
function setProp(prop,val){
arguments.callee.caller.prototype[prop]=val;
}
function Person(){
setProp('birthday',new Date());
return this;
}
Wanted ES6 : ✘
function setProp(prop,val){
arguments.callee.caller.prototype[prop]=val; //--- Throw ERROR
//Another attempt : arguments.callee(true).caller[prop]=val //--- throw Error
}
class Person{
constructor(){
setProp('birthday',new Date())
}
}
We try to convert setProp
to arrow-function . however this
means window
and arguments
is undefined there
Aucun commentaire:
Enregistrer un commentaire