Bart

ECMAScript 6: Destructuring

by @mikaelbrevik for Meetup #3 Bart.JS. April 3rd 2014.

Destructuring!

  • Proposed back in ES4 (2006!)
  • Originally from LISP?
  • Subset of pattern matching

In different languages with different names

  • Python: unpacking
  • Ruby: parallel assigning
  • PHP: listing
  • Functional languages: destructuring bind

Destructuring lists and arrays

Normal arrays

Ctrl + S to run selected

Fail safe & Combine with rest

Ctrl + S to run selected

More Advanced Arrays

Ctrl + S to run selected

With Objects?

Ctrl + S to run selected
Ctrl + S to run selected

More advanced object literals

Ctrl + S to run selected

Used as parameter (!!)

Ctrl + S to run selected

Can also use with the advanced example

Ctrl + S to run selected

In combination with other ES6 features

Short-hand in parameter with defaults

Ctrl + S to run selected

Some issues with fat-arrow

Ctrl + S to run selected

Like underscore/lodash pluck

Ctrl + S to run selected

With array comprehension and default values

Ctrl + S to run selected

Spørsmål?

https://github.com/bartjs

http://bartjs.github.io/