日本免费高清视频-国产福利视频导航-黄色在线播放国产-天天操天天操天天操天天操|www.shdianci.com

學無先后,達者為師

網站首頁 編程語言 正文

es6及之后的剩余參數

作者:Wxinin 更新時間: 2022-04-23 編程語言

注意:箭頭函數中沒有arguments,在箭頭函數中打印arguments會向上層作用域去找(全局中的node環境存在arguments,瀏覽器中沒有arguments打印會報錯)

function foo() {
  var bar = () => {
    console.log(arguments)
  }
  return bar
}

var fn = foo(123)
fn()//123--箭頭函數本身沒有arguments,打印的是上層作用域foo的arguments

在es6之后,想要傳額外的多個參數,用到args(剩余參數)
前兩個會對應匹配,剩下的全都放到args數組中

var foo = (num1, num2, ...args) => {
  console.log(args)
}

foo(10, 20, 30, 40, 50)//[30,40,50]

在這里插入圖片描述

原文鏈接:https://blog.csdn.net/weixin_44283589/article/details/123798037

欄目分類
最近更新