Ecma262: Auto object destructuring

Created on 8 Dec 2019  路  3Comments  路  Source: tc39/ecma262

Let's say we have data object someDescriptiveName and we need to destructure it multiple times in different functions with the purpose of being able to use shorter property names.

For example:

property1 Instead of this.someDescriptiveName.property1

Data

someDescriptiveName: {
  property1: false,
  property2: false,
  property3: false,
  property4: false,
  property5: false,
}

Current method

function func1() {
  let {
    property1,
    property2,
    property3,
    property4,
    property5,
  } = this.someDescriptiveName
  console.log(property1)
}

function func2() {
  let {
    property1,
    property2,
    property3,
    property4,
    property5,
  } = this.someDescriptiveName
  console.log(property1)
}

Proposed method

function func1() {
  let {*} = this.someDescriptiveName
  console.log(property1)
}

function func2() {
  let {*} = this.someDescriptiveName
  console.log(property1)
}
feature suggestion

Most helpful comment

@AlexSHoffman This exists: it鈥檚 the with statement. It鈥檚 disallowed in strict mode because it leads to a variety of problems.

All 3 comments

Thanks for the feature suggestion! Please see https://github.com/tc39/ecma262/blob/master/CONTRIBUTING.md#creating-a-new-proposal for how to best suggest new features to the language (also, the "feature request" issue template you modified to post this issue).

@AlexSHoffman This exists: it鈥檚 the with statement. It鈥檚 disallowed in strict mode because it leads to a variety of problems.

@bathos thanks for letting me know about this

Was this page helpful?
0 / 5 - 0 ratings