0

In Javascript, is it possible to destructure an object with "delete" as one of its properties?

class MyClass {

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

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

    }

}
Paulo Coghi
  • 13,724
  • 14
  • 68
  • 90

1 Answers1

3

delete is a reserved keyword, you cannot have that as a variable name. Therefore you have to rename it during destructuring:

  { delete: otherName }
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151