如何为重命名 解构变量分配默认值:
class MyClass {
constructor ( { prop1, prop2, delete: remove, prop4 } ) {
this.prop1 = prop1
this.prop2 = prop2
this.delete = delete
this.prop4 = prop4
}
}
最佳答案
正常解构的默认值和解构为不同名称之间没有区别:
constructor ( { prop1 = true, prop2 = false, delete: remove = true, prop4 = 'something' } ) {
或者你只是去:
const defaults = { /*...*/ };
constructor(settings) {
Object.assign(this, defaults, settings);
}
并避免所有这些麻烦:)
关于javascript - 为重命名的解构变量分配默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55907285/