使用 "delete" 作为 属性 解构对象

Destructuring an object with "delete" as property

在 Javascript 中,是否可以解构具有 "delete" 作为其属性之一的对象?

class MyClass {

    constructor ( { prop1, prop2, delete, prop4 } ) {

        this.prop1  = prop1
        this.prop2  = prop2
        this.delete = delete
        this.prop4  = prop4

    }

}

delete 是保留关键字,您不能将其作为 变量名 。因此你必须在解构期间重命名它:

  { delete: otherName }