【前端学习笔记】arguments相关

arguments转数组:

(function() {
	  console.log(arguments instanceof Array); // --> false
	  console.log(Object.prototype.toString.call(arguments)); // --> [object Arguments]
  var args = Array.prototype.slice.apply(arguments);
	  console.log(args instanceof Array); // --> true
	  console.log(Object.prototype.toString.call(args)); //--> [object Array]
  args.forEach(function(item){
    console.log(item);
  })
})(1,2,3);

arguments.callee使用:

/* arguments.callee使用 */
  (function(i){
    if (i==0) {
      return 1;
    }
    return i*arguments.callee(i-1);
  })(5);

//等价于下面递归
// /* 递归 */
function factorial(i){
  if (i==0) {
    return 1;
  }
  return i*factorial(i-1);
}
factorial(5);

 

  

 

posted @ 2016-11-12 18:23  朱两边  阅读(234)  评论(0编辑  收藏  举报