{
//函数的新增特性
// 参数默认值 rest参数 扩展运算符 箭头函数 this绑定 尾调用
function test(x,y='world'){//参数默认值 如果没有第二个参数 就拿默认参数
console.log('默认值',x,y)
}
test('hello')
test('hello','xiaohao')
}
{
let x = 'test';//参数默认值
function test2(x,y=x){//如果参数中有声明变量 参数读取参数值 如果没有则读取变量值
console.log('作用域',x,y)
}
test2('xiaohao')
}
{
function test3(...arg){ //arguments对象不是数组,只是可以下标访问而已,而rest参数是一个真正的数组。
console.log(typeof arg)//rest参数,形式为:...变量名
for(let i of arg){
console.log('rest',i)
}
}
test3(1,2,3,5,6,7,8,9)
}
{
console.log(...[1,2,3,4,5,6])//扩展运算符为rest参数的逆用法 把数组转为零散的值
console.log('a','b',...[1,2,3,4,5,6])
}
{//箭头函数
let fun1 = ()=>{return 5}
console.log(fun1())
let fun = v => v*2 //左边为函数名 中间v为参数 右边为函数体 没有参数为括号
console.log(fun(6))
}
{ //尾调用写法 某个函数的最后一步是调用另一个函数 参考阮大神解释
function a(x){
console.log(x)
}
function b(x){
return a(x)
}
b('xiaohao')
}