현재 번역은 완벽하지 않습니다. 한국어로 문서 번역에 동참해주세요.
Summary
length 속성은 함수에 정의된 인자의 수를 나타냅니다.
Property attributes of Function.length |
|
|---|---|
| Writable | no |
| Enumerable | no |
| Configurable | yes |
Description
length는 함수객체의 속성으로 함수가 기대하고 있는 인자 즉 함수의 정의에서 직접 정의된 인자가 몇개인지를 알려줍니다. rest parameter형식으로 지정된 인자의 경우는 0이 됩니다. 반대로 arguments.length가 함수의 지역 범위에서 사용되며 함수가 호출될 때 전달된 실제 인자의 갯수를 알려줍니다.
Function객체의 생성자에 있는 속성값
Function의 생성자는 Function 그 자신입니다. 이 때 length값은 1입니다. 이 속성은 다음과 같이 정의됩니다: Writable: false, Enumerable: false, Configurable: true.
Function의 prototype객체의 속성값
Function의 prototype 객체에 있는 length속성의 값은 0입니다.
Examples
console.log(Function.length); /* 1 */
console.log((function() {}).length); /* 0 */
console.log((function(a) {}).length); /* 1 */
console.log((function(a, b) {}).length); /* 2 etc. */
console.log((function(...args) {}).length); /* 0, rest parameter is not counted */
Specifications
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 1st Edition. | Standard | Initial definition. Implemented in JavaScript 1.1. |
length property of the Function constructor:ECMAScript 5.1 (ECMA-262) The definition of 'Function.length' in that specification. length property of the Function prototype object:ECMAScript 5.1 (ECMA-262) The definition of 'Function.length' in that specification. length property of Function instances:ECMAScript 5.1 (ECMA-262) The definition of 'Function.length' in that specification. |
Standard | |
length property of the Function constructor:ECMAScript 6 (ECMA-262) The definition of 'Function.length' in that specification. length property of the Function prototype object:ECMAScript 6 (ECMA-262) The definition of 'Function.length' in that specification. length property of Function instances:ECMAScript 6 (ECMA-262) The definition of 'Function.length' in that specification. |
Release Candidate | The configurable attribute of this property is now true. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
| Configurable: true | ? | 37 (37) | ? | ? | ? |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
| Configurable: true | ? | ? | 37.0 (37) | ? | ? | ? |