zoukankan      html  css  js  c++  java
  • arguemnts的初步理解

    1.只能在函数内部使用
    2.类数组,Array.prototype.slice.call(arguments)转化为数组,
    3.arguments的值只和执行的时候传入的参数有关如果传入的参数是(1,2,3),那么Array.prototype.slice.call(arguments)=[1,2,3],跟定义函数的参数没一毛钱关系;
    4.非严格模式下,函数执行的时候,arguments的值和形参相互影响

    function t(a){
      console.log(arguments);
      console.log(a);
      arguments[0]=2;
      console.log(arguments);
      console.log(a);
      a=3;
      console.log(arguments);
      console.log(a);
    }

    5.arguments的使用:参数数量不固定的时候,且是同种类型的时候,可以使用,累积累加什么的

    function concatStr(seperator){
      var sum = "";
      return Array.prototype.slice.call(arguments,1).join(seperator);
    }
    console.log(concatStr("-","start","end"))

  • 相关阅读:
    第17章 委托
    第16章 数组
    第15章 枚举类型和位标志
    第14章 字符、字符串和文本处理
    第13章 接口
    第12章 泛型
    第10章 属性
    第11章 事件
    内部类(转载)
    Collections.sort的三种用法
  • 原文地址:https://www.cnblogs.com/2han/p/6277623.html
Copyright © 2011-2022 走看看