I have next class in many function in it :
class EventUtils {
constructor(pid) {}
bindEvent1{}
bindEvent2()
...
}
I have to run those functions. Before ES5 I used something like this or this methods
However, after rewriting to ES6 classes those examples are not working any more. I had tried next code:
let eventUtils = new EventsUtils();
Object.getOwnPropertyNames(eventUtils.__proto__).forEach((name) => {
if (name.indexOf('bind') > -1) {
let fn = eventUtils[name];
if (typeof fn === "function") fn.apply(null);
}
});
But in such way I the scope of this
is not defined in applied function.
What is the right way to do such coding?