Just like with arrays, objects can be destructured as well. The main difference is the use of curly braces instead of square brackets. Kyle demonstrates a shorter notation for when the variable name in the target object matches the variable name in the destructured object.
So let's reset back to the case with objects.…And a lot of this is gonna start to be more self-explanatory…now cause you already know what to expect,…cause we've seen it with arrays.…A lot of the same things are gonna be true.…We could have done this as tmp dot…and tmp dot b.…And tmp dot c, okay?…That would have been the pre-ES6 equivalent.…
Now what we can do is take this function…and we can do an object destructuring.…So I'm gonna do an object pattern…with curly braces instead of brackets.…And in my object pattern, I'm going to say,…I want the a property…to be targeted to…an a assignment location.…Okay?…And I want b to go to b, and I want c to go to c.…
In the case where our target and our source are the same…meaning we don't need to do any alias or renaming,…we do not have to specify them twice.…We can just simply say, a, b, c.…It will assume that means, go get the property of name a…and assign it to a variable called a, okay?…But if we wanted to, for example,…reassign the b property…instead to a variable called capital X,…
This course was created by Frontend Masters. It was originally released on 01/10/2017. We're pleased to host this training in our library.
- The arrow function
- Arrow function variations
- Closures and explicit blocks
- Default values
- Using the gather and spread operators
- Dumping variables
- Concise properties and methods
- Symbols, iterators, and generators
- Optimizing codes for the reader
Skill Level Intermediate
1. Arrow Functions
2. Block Scope
3. Default Values and the Gather/Spread Operators
5. Template Strings
6. Symbols, Iterators, and Generators
- Mark as unwatched
- Mark all as unwatched
Are you sure you want to mark all the videos in this course as unwatched?
This will not affect your course history, your reports, or your certificates of completion for this course.Cancel
Take notes with your new membership!
Type in the entry box, then click Enter to save your note.
1:30Press on any video thumbnail to jump immediately to the timecode shown.
Notes are saved with you account but can also be exported as plain text, MS Word, PDF, Google Doc, or Evernote.