I have this function outside of class in a global scope.
function toggleDescriptor(key, descriptors = 0){
let _a, _b, _c;
if (descriptors) [_a, _b, _c] = descriptors;
else [_a, _b, _c] = ["writable", "enumerable", "configurable"];
if(this[key] == undefined){
__defprty(this, key, {[_a] : true, [_b] : true, [_c] : true});
}
else{
__defprty(this, key, {[_a] : false, [_b] : false, [_c] : false});
}
}
And I call this in a class like this :
class Application {
constructor(state){
this.interface = new Interface(this);
this.interface.state = state;
toggleDescriptor("interface"); //this not works...
}
run(){
this.interface.state.handle();
}
}
However, this
in toggleDescriptor contains window
not Application
class. I guess it always set this
as window
object. But I want to keep this function outside so that other class can use it without redundantly having this function. So, how can I make toggleDescriptor
indicating the Application
when it's called in the Application
class?