首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

arguments.length

arguments.length属性包含传递给该函数的参数的数量。

语法

代码语言:javascript
复制
arguments.length

描述

arguments.length表示的是实际上向函数传入了多少个参数,这个数字可以比形参数量大,也可以比形参数量小(形参数量的值可以通过Function.length获取到).

示例

使用arguments.length

这个例中,我们定义了一个可以相加任意个数字的函数.

代码语言:javascript
复制
function adder(base /*, n2, ... */) {
  base = Number(base);
  for (var i = 1; i < arguments.length; i++) {
    base += Number(arguments[i]);
  }
  return base;
}

注意Function.length和arguments.length 之间的区别

规范

Specification

Status

Comment

ECMAScript 1st Edition (ECMA-262)

Standard

Initial definition. Implemented in JavaScript 1.1

ECMAScript 5.1 (ECMA-262)The definition of 'Arguments Object' in that specification.

Standard

?

ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'Arguments Exotic Objects' in that specification.

Standard

?

ECMAScript Latest Draft (ECMA-262)The definition of 'Arguments Exotic Objects' in that specification.

Living Standard

?

浏览器兼容性

Feature

Chrome

Firefox (Gecko)

Internet Explorer

Opera

Safari

Basic support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

Feature

Android

Chrome for Android

Firefox Mobile (Gecko)

IE Mobile

Opera Mobile

Safari Mobile

Basic support

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

(Yes)

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com