Skip to content

Instantly share code, notes, and snippets.

@thisiswei
Last active November 26, 2018 02:58
Show Gist options
  • Save thisiswei/5422a6b74d43afbb45adaabbc1918b53 to your computer and use it in GitHub Desktop.
Save thisiswei/5422a6b74d43afbb45adaabbc1918b53 to your computer and use it in GitHub Desktop.
es6
// https://ponyfoo.com/articles/es6#introduction
> [a, , b] = [0,1,2]
[ 0, 1, 2 ]
> a
0
> b
2
> function blah(a, b,...rest) {return rest;}
undefined
> blah(1,2,{a: 'a'})
[ { a: 'a' } ]
> blah(1,2,{a: 'a'}, {b: 'b'})
[ { a: 'a' }, { b: 'b' } ]
>
// Avoids .apply when calling methods, fn(...[1, 2, 3]) is equivalent to fn(1, 2, 3)
> blah(...[1,2,3,4,5])
[ 3, 4, 5 ]
// Easier concatenation [1, 2, ...[3, 4, 5], 6, 7]
> [1,2, ...[3,4,5], 6,7]
[ 1, 2, 3, 4, 5, 6, 7 ]
> [1,2].map(x => x*2)
[ 2, 4 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment