ES6初识-函数扩展

时间:2023-03-09 08:16:59
ES6初识-函数扩展
  • 默认值
function test(x,y='world'){
console.log('默认值');
}
function test2(...arg){
for(let v of arg){
console.log("rest",v);
}
}
test2(1,2,3,4,5,'a');
  • 箭头函数
let arrow =v=>v*2;
console.log('arrow',arrow(3));//6
  • 尾调用---性能优化的过程中,嵌套过多
function tail(x){
console.log('tail',x);
}
function fx(x){
return tail(x);
}
fx(123);