美文网首页
arguments小笔记

arguments小笔记

作者: _嗯_哼_ | 来源:发表于2018-01-09 18:02 被阅读0次

为什么说arguments是伪(类)数组?
答:因为arguments它不是数组,却用起来像数组,有length属性和[ ]访问成员。但是不具有数据的方法,如join()concat()等。。。

怎样将arguments转换成数组

Array.prototype.slice.apply(arguments)
image.png

转换前


image.png

转换后


image.png

1、数组长度

window.onload = function(){

        function abc(){
            console.log(arguments.length)
        }
        abc(1,2,3)

  }// 3

2、改变参数值

window.onload = function(){

        function abc(x,y,z){
              arguments[2] = "hello";
              for(var i=0;i<=arguments.length;i++){
                    console.log(" "+arguments[i]);
              }

          }
        abc(1,2,3)

  }// 1,2,hello

3、递归(callee()调用自身)

求1到n的自然数之和

function add(x){
            if(x == 1) return 1;
            else return x + arguments.callee(x-1);
         }
         console.log(add(5))//15

对于没有命名的函数

var result = function(x){
              if(x == 1) return 1;
              return x+arguments.callee(x-1);
          }
         console.log(result(5))//15

相关文章

  • arguments小笔记

    为什么说arguments是伪(类)数组?答:因为arguments它不是数组,却用起来像数组,有length属性...

  • 【JS】函数实参与形参

    本节目录 形参 实参 arguments的特性 arguments的非标准用法 arguments小案例 1.形参...

  • 笔记(四)--arguments

    1.arguments对象介绍 arguments 凡是函数调用,默认含有一个 arguments 对象,可以将其...

  • 1.arguments 1.1arguments怎么理解 arguments对象是所有(非箭头)函数中都可用的局部...

  • js中arguments的用法

    arguments特性 **arguments **对象不能显式创建, **arguments **对象只有函数开...

  • Python新起航

    Arguments Immutable arguments are effectively passed “by ...

  • javascript arguments、callee、cal

    arguments、calle、caller基本使用 本文是作者的学习笔记、主要是给大家说说callee与call...

  • js arguments

    arguments 就是所有的参数arguments 和参数共存!!!!!!arguments 简单应用 argu...

  • 2018-11-22 关于 arguments.callee

    arguments.callee 函数内, 有两个特殊对象: arguments 和 this arguments...

  • javaScript 基础 04

    函数 1.arguments arguments JavaScript还有一个免费赠送的关键字arguments,...

网友评论

      本文标题:arguments小笔记

      本文链接:https://www.haomeiwen.com/subject/bedgnxtx.html