JS中的arguments对象


一、arguments是什么?

arguments是所有函数都具有的一个内置局部变量,表示的是函数实际接收的参数对象。arguments是一个类数组对象,之所以称为类数组对象,是因为他除了数组所具有的length属性外,并没有数组本身自带的其他方法。

二、arguments对象详解

1.arguments的使用

//arguments对象
    getArguments(a: any, b: any) {
        console.log(arguments);
        const arr = [...arguments];//可以将类数组转换为数组获得含有实参的数组
        console.log(arr); //[12,11]
        console.log(arguments[0]); //12
        console.log(arguments[1]); //11
        console.log(arguments[2]); //undefined
        //指定的形参传递值的情况下,arguments对象与形参值相同,并且可以相互改变。
        arguments[0] = 1;
        console.log(arguments);
    }


//调用该函数并传入参数
 this.getArguments(12, 11);


输出为:

实参在arguments类数组中

2.指定的形参传递值的情况下,arguments对象与形参值相同,并且可以相互改变。

//arguments对象
    getArguments(a: any, b: any) {
        //指定的形参传递值的情况下,arguments对象与形参值相同,并且可以相互改变。
        arguments[0] = 1;
        console.log(arguments);
    }


//调用该函数并传入参数
 this.getArguments(12, 11);

输出为:

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值