1

So consider the following snippet

const x = {
     name: 'somebody'
};

const { name as somePerson } = x;  // Would be awesome to have something like this
manju4ever
  • 325
  • 1
  • 13
  • Side note: The JavaScript specification doesn't have RFCs (that I know of). There's this thing called the TC39 committee that has a standard process for approving proposals to the ECMAScript language specification. – Patrick Roberts Feb 16 '18 at 08:39
  • You should always refer to **[docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring)** first. They usually have solution for most common problem. – Rajesh Feb 16 '18 at 09:03

1 Answers1

3

You could change the target in the Object Property Assignment Pattern [You Don't Know JS: ES6 & Beyond, Chapter 2: Syntax]:

The syntactic pattern here is source: target (or value: variable-alias).

{ name: somePerson }

const x = {
     name: 'somebody'
};

const { name: somePerson } = x;

console.log(somePerson);
Nina Scholz
  • 376,160
  • 25
  • 347
  • 392