Hy all,
sometimes the JS-implementation of this is real strange. In callback functions, this is bound to the caller, not the object that defined the function. I found this very helpful to makes things more consistent:
// bind all methods to the constructor functionautobind(instance){letproto=Object.getPrototypeOf(instance);letpropertyNames=Object.getOwnPropertyNames(proto);for(letnameofpropertyNames){letvalue=proto[name];if((typeofvalue==='function')){if(name!=='constructor')instance[name]=proto[name].bind(instance);}}}
This is used in the constructor:
classtest{constructor(){autobind(this)// bind all methods to the constructor....
Hy all,
sometimes the JS-implementation of this is real strange. In callback functions, this is bound to the caller, not the object that defined the function. I found this very helpful to makes things more consistent:
This is used in the constructor:
This function is part of my DML-framework too...