ECMAScript arguments对象

2016-11-20  本文已影响15人  LYF闲闲闲闲

1.arguments是什么?

2.arguments有什么用?

代码

function addAll(){
  let sum = 0;
  for(let i=0;i<arguments.length;i++){
     sum +=arguments[i];
  }
  console.log(sum);
}
addAll(10,20);

3.如果我们在函数中自己定义了一个名为arguments的变量,会出现什么情况?

4.callee属性

callee属性是一个指针,指向拥有这个arguments对象的函数

function fac(num){
  if( num <= 1 ){
    return 1;
  } else{
    return num*arguments.callee(num-1);
  }
}
let newFac = fac;
fac = function(){
  return 0;
}
alert(newFac(5));  //120
alert(fac(5));     //0      
上一篇 下一篇

猜你喜欢

热点阅读