0%

参数处理&解构赋值

函数默认参数

与 Python 的区别 http://effbot.org/zone/default-values.htm
剩余参数

参数变为数组

Array.prototype.slice.call(arguments,2)
Array.from(arguments).slice(2)
function fn (a,b, …c){}
展开操作

[…iterableObj] = [1, 3, 5, 7, 9];
[0, 2, …iterableObj, 4, 6, 8];

解构赋值

[a, b] = [b, a]

[] () 前最好加;

[a, b, …rest] = [10, 20, 30, 40, 50]
let {name, age} = frank
[a=5, b=7] = [1];
[a, b] = f()
[a, , b] = f();
{p: foo, q: bar} = o
let {a = 10, b = 5} = {a: 3};
let {a:aa = 10, b:bb = 5} = {a: 3};

对象浅拷贝

1
2
3
4
5
6
7
{
let objA = {name: {a: 'x'}}
let objB = Object.assign({}, objA)
console.log(objB)
objB.name.a = 'b'
console.log(objA.name)
}//b

对象合并
MDN 上更多的例子

对象属性加强

obj = { x, y }
obj = {[“baz” + quux() ]: 42}
函数属性可以缩写

新的字符串

多行字符串
字符串里插入变量(插值)
函数接字符串

fn${name} 是一个 ${person}
styled-component 就是用的这个语法