-
-
Save thisiswei/5422a6b74d43afbb45adaabbc1918b53 to your computer and use it in GitHub Desktop.
es6
This file contains hidden or 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
// 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