Skip to content

Instantly share code, notes, and snippets.

@juliocesar
Created May 3, 2013 04:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juliocesar/5507216 to your computer and use it in GitHub Desktop.
Save juliocesar/5507216 to your computer and use it in GitHub Desktop.
ES6 - destructuring
// ES6 destructuring
// =================
// Assume a Person "class".
Person.prototype.giveTwoThings = function() {
return ['This', 'That']
}
// var [a, b] = p.giveTwoThings()
// a
// => 'This'
// b
// => 'That'
// Also possible to pull object properties out. That's in node.js already.
// var p = new Person('Julio')
// var {name} = p;
// name
// => "Julio"
// You can destructure in loops too:
// var fruits = [ { name: 'Apple', color: 'red' }, { name: 'Banana', color: 'yellow' }];
// fruits.forEach(
// function({name: name, color: color} { console.log(name + ': ' + color)})
// )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment