Hayk Safaryan
Hayk Safaryan

Reputation: 2056

Create ES6 Class Methods from other class methods

So I have a class with a curried method

class myClass {
  constructor () {}

  curry (a,b) {
    return (a,b) => {}
  }

}

Now can create another method with the curry? Something like this

class myClass {
  constructor () {}

  curry (a,b) {
    return (a,b) => {}
  }

  newMethod = curry()
}

Upvotes: 1

Views: 1265

Answers (1)

Bergi
Bergi

Reputation: 665276

Yes, you can easily do that - just put it in the constructor:

class MyClass {
  constructor() {
    this.newMethod = this.curriedMethod('a') // partial application
  }

  curriedMethod(a) {
    return (b) => {
      console.log(a,b);
    }
  }
}

let x = new MyClass();
x.newMethod('b')

Upvotes: 5

Related Questions