Skip to content

Instantly share code, notes, and snippets.

@MikeMKH
Created May 30, 2015 19:01
Simple examples of destructuring in ES6
// http://babeljs.io/
// http://shouldjs.github.io/
import * as should from 'should';
let bilbo = {
name: 'Bilbo',
age: 50,
family: ['Baggins', 'Took'],
pastTime: ['writing']};
let {name, family:parents} = bilbo;
name.should.equal('Bilbo');
parents.should.eql(['Baggins', 'Took']);
let hobbies = ({name, pastTime:hobbies}) => name + ' enjoys ' + hobbies.join(', ');
hobbies(bilbo).should.equal('Bilbo enjoys writing');
hobbies({
name: 'Gollum',
something: 'else',
pastTime: ['precious!']}).should.equal('Gollum enjoys precious!');
@MikeMKH
Copy link
Author

MikeMKH commented May 30, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment