Created
February 16, 2016 13:38
-
-
Save KKrisu/e0a92e881b6b042ecaef to your computer and use it in GitHub Desktop.
ES6 Deconstructing
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
// # Arrays | |
// var a = ['a', 'b', 'c']; | |
// var i = a[0]; | |
// var j = a[1]; | |
// var k = a[2]; | |
// var [i, j, k] = a; | |
// var [i, j, k] = ['a', 'b', 'c']; | |
// console.log(i, j, k); | |
// var a = 3; | |
// var b = 5; | |
// [b, a] = [a, b]; | |
// console.log(a, b); | |
// function f1() { | |
// return ['foo', 'bar']; | |
// } | |
// var [a, b] = f1(); | |
// console.log(a, b); | |
// var [i, , j] = ['a', 'b', 'c', 'd']; | |
// console.log(i, j); | |
// # OBJECTS | |
// var o = {a: 1, b: 2}; | |
// // var {a, b} = o; | |
// var {a, b} = {a: 1, b: 2}; | |
// console.log(a, b); | |
// var {a: i, b: j} = {a: 1, b: 2}; | |
// console.log(i, j); | |
// #Default functions parameters | |
// function f1(a, b) { | |
// a = a === undefined ? 3 : a; | |
// b = b || 5; | |
// console.log(a, b); | |
// } | |
// f1(0); | |
// function f2(a = [1, 2, 3], b = {a: a, b: 2}) { | |
// a.push(4); | |
// console.log(a, b); | |
// } | |
// f2(); | |
// function f3({position = {x: 0, y: 0}, width = 1, height = 1} = {}) { | |
// console.log(position, width, height); | |
// } | |
// f3({ | |
// height: 4, | |
// }); | |
// # Strings | |
// var [a, , b] = 'ijk'; | |
// console.log(a, b); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment