0

Given the class below as an example:

class BestClassEver {
    constructor() {
        let self = this;
        self.doSomethingOne = self.doSomethingOne.bind(self);
        self.doSomethingTwo = self.doSomethingTwo.bind(self);
        self.doSomethingThree = self.doSomethingThree.bind(self);
        self.doSomethingFour = self.doSomethingFour.bind(self);
        self.doSomethingFive = self.doSomethingFive.bind(self);
    }

    doSomethingOne(){
        ...
    }
}

Is there a way to simplify this? If I had 20 methods it could get lengthy. Unless there is a way to automatically bind methods to this like an arrow function would. I've tried to use arrow functions but my compiler throws errors.

Josh
  • 1,455
  • 19
  • 33

0 Answers0