length 속성은 함수가 기대하는 인수의 수를 나타냅니다.
Property attributes of Function.length |
|
|---|---|
| Writable | no |
| Enumerable | no |
| Configurable | yes |
설명
length는 함수 객체의 속성으로, 함수가 얼마나 많은 인수를 기대하는지 나타냅니다, 즉 형식 매개변수의 수. 이 수는 나머지 매개변수를 포함하지 않습니다. 그에 반해, arguments.length는 함수에 지역(local)이고 실제로 함수에 전달된 인수의 수를 제공합니다.
Function 생성자의 데이터 속성
Function 생성자는 그 자체로 Function 객체입니다. 그 length 데이터 속성은 값이 1입니다. 속성의 attribute: 쓰기가능(Writable): false, 열거가능(Enumerable): false, 설정가능(Configurable): true.
Function 프로토타입 객체의 속성
Function 프로토타입 객체의 length 속성은 값이 0입니다.
예제
console.log(Function.length); /* 1 */
console.log((function() {}).length); /* 0 */
console.log((function(a) {}).length); /* 1 */
console.log((function(a, b) {}).length); /* 2 등. */
console.log((function(...args) {}).length); /* 0, 나머지 매개변수는 계산되지 않음 */
명세
| 스펙 | 상태 | 설명 |
|---|---|---|
| ECMAScript 1st Edition (ECMA-262) | Standard | 초기 정의. JavaScript 1.1에서 구현됨. |
| ECMAScript 5.1 (ECMA-262) The definition of 'Function.length' in that specification. |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Function.length' in that specification. |
Standard | 이 속성의 설정가능(configurable) attribute은 이제 true임. |
| ECMAScript Latest Draft (ECMA-262) The definition of 'Function.length' in that specification. |
Draft |
브라우저 호환성
Update compatibility data on GitHub
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
length | Chrome Full support Yes | Edge Full support 12 | Firefox Full support 1 | IE Full support Yes | Opera Full support Yes | Safari Full support Yes | WebView Android Full support Yes | Chrome Android Full support Yes | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support Yes | nodejs Full support Yes |
| Configurable: true | Chrome ? | Edge ? | Firefox Full support 37 | IE ? | Opera ? | Safari ? | WebView Android ? | Chrome Android ? | Firefox Android Full support 37 | Opera Android ? | Safari iOS ? | Samsung Internet Android ? | nodejs ? |
Legend
- Full support
- Full support
- Compatibility unknown
- Compatibility unknown