mjavascript / practical-modern-javascript

🏊 Dive into ES6 and the future of JavaScript

Home Page:https://mjavascript.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

chapter 2: code examples and descriptions are miscoordinated

vsemozhetbyt opened this issue · comments

It seems there is a conflict between some editions:

Consider the next snippet, where a property named code wouldn’t have been as indicative of its contents as colorCode could be:

var { metadata: { gender: characterGender } } = character

The scenario we just saw repeats itself frequently, because properties are often named in the context of their host object. While palette.color.code is perfectly descriptive, code on its own could mean a wide variety of things, and aliases such as colorCode can help you bring context back into the variable name while still using destructuring.

Also:

In the following example we use the value alias, and a computed property name to extract the boots property from the character object.

var { ['boo' + 'ts']: characterBoots } = character
console.log(characterBoots)
// <- true