This question already has answers here:
How to destructure object properties with key names that are invalid variable names?
                                
                                    (2个答案)
                                
                        
                4个月前关闭。
            
        

在Javascript中,是否可以使用“删除”作为其属性之一来破坏对象?

class MyClass {

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

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

    }

}

最佳答案

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

  { delete: otherName }

关于javascript - 使用“删除”作为属性来破坏对象,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55906855/

10-11 20:48