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"))

 

posted @ 2017-01-12 12:02  花.花  阅读(133)  评论(0编辑  收藏  举报