从其他 class 方法创建 ES6 Class 方法
Create ES6 Class Methods from other class methods
所以我有一个 class 和一个咖喱方法
class myClass {
constructor () {}
curry (a,b) {
return (a,b) => {}
}
}
现在可以用咖喱创建另一种方法吗?像这样
class myClass {
constructor () {}
curry (a,b) {
return (a,b) => {}
}
newMethod = curry()
}
是的,您可以轻松做到这一点 - 只需将其放入构造函数中即可:
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')
所以我有一个 class 和一个咖喱方法
class myClass {
constructor () {}
curry (a,b) {
return (a,b) => {}
}
}
现在可以用咖喱创建另一种方法吗?像这样
class myClass {
constructor () {}
curry (a,b) {
return (a,b) => {}
}
newMethod = curry()
}
是的,您可以轻松做到这一点 - 只需将其放入构造函数中即可:
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')