ES5中的arguments

 

function func(a,b,c){
  console.log(arguments[0],arguments[1],arguments[2]) 
}
func(1,2,3) //1,2,3

 

在使用箭头函数时,arguments 指向的对象并不是当前函数所属的argments,而是上级函数的arguments,可以使用剩余运算符(rest)来替代,详情见:https://www.cnblogs.com/vickylinj/p/11739473.html

 

let func = (...rest) => {
  console.log(rest)
}
func(1,2,3)  //[1,2,3]

 

相关文章:

  • 2022-12-23
  • 2021-11-02
猜你喜欢
  • 2022-12-23
  • 2022-01-22
  • 2022-12-23
  • 2021-12-24
  • 2021-10-27
  • 2022-12-23
相关资源
相似解决方案