Created
March 27, 2015 23:52
-
-
Save keokilee/61db699057d4485c5ed8 to your computer and use it in GitHub Desktop.
ES6 Destructuring
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Assign first and second to the first two values in the array. | |
var nums = [1, 2, 3]; | |
var firstES5 = nums[0]; | |
var secondES5 = nums[1]; | |
var [firstES6, secondES6] = nums; | |
// Assign the foo and bar properties from the object. | |
var object = {foo: 1, bar: 2}; | |
// ES5 | |
var foo = object.foo; | |
var bar = object.bar; | |
// ES6: This pattern matches the variable name to the object property | |
var {foo, bar} = object; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment