首页 > 其他 > 详细

【前端学习笔记】arguments相关

时间:2016-11-12 20:14:05      阅读:138      评论:0      收藏:0      [点我收藏+]

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

 

  

 

【前端学习笔记】arguments相关

原文:http://www.cnblogs.com/zachary93/p/6057259.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!