js中的argument

來源:互聯網
上載者:User

標籤:

在函數體內,標識符arguments是指向實參對象的引用,實參對象是一個類數組對象 arguments[0],arguments.length

  arguments是什麼?
  答:1:arguments是收到的實參副本
  在詞法分析中, 首先按形參形成AO的屬性,值為undefined
  當實參傳來時, 再修改AO的相應屬性.
  2:並把所有收到實參收集起來,放到一個arguments對象裡
  t(a,b,c){},
  調用時: t(1,2,3,4,5) 5個參數
  此時 , AO屬性只有a,bc,3個屬性, arguments裡有1,2,3,4,5, 所有的值

  對於超出形參個數之外的實參, 可以通過arguments來獲得
  3:arguments 的索引 從 0, 1,2,....遞增,與實參逐個對應
  4:arguments.length 屬性代表實參的個數
  5:arguments一定不是數組, 是長的比較像數組的一個對象,雖然也有length屬性
  6:arguments每個函數都會有,因此,arguemnts只會在內部找自身的arguments,
  無法引用到外層的arguments
  <script type="text/javascript">
  // 求圓形面積,矩形面積, 三角形面積
  function area () {
  if(arguments.length == 1) {
  alert(3.14 * arguments[0] * arguments[0]);
  } else if(arguments.length == 2) {
  alert(arguments[0] * arguments[1]);
  } else if(arguments.length == 3) {
  alert(arguments[0] + arguments[1] + arguments[2]);
  } else {
  return null;
  }
  }
  area(10,20,30);
  
  </script>

js中的argument

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.