是否有类似于数组解构赋值的东西,但用于类定义?
代码可能如下所示:
class Foo {
[value, setValue] = createField("someString");
}
我能想到的最接近的是Object.assign:
class Foo {
constructor() {
Object.assign(this, createField("someString"))
}
}
其中
createField
返回一个对象,例如:
function createField (param) {
return {
value: 'foo',
setValue: () => { /* ... */ }
}
}