Function.length
Baseline
Widely available
This feature is well established and works across many devices and browser versions. Itâs been available across browsers since 2015å¹´7æ.
length property 表示該 function é æè¢«å³å
¥ç忏æ¸é
Function.length ç屬æ§ç¹æ§ | |
|---|---|
| å¯å¯« | å¦ |
| å¯åè | å¦ |
| å¯é ç½® | æ¯ |
æè¿°
length æ¯ function ç©ä»¶çä¸å propertyï¼è¡¨ç¤ºè©² function é æè¢«å³å
¥ç忏æ¸éï¼é忏é並ä¸å
å« rest parameter ä¸åªå
涵第ä¸åé è¨åæ¸(Default Parameters)åç忏ãç¸è¼ä¹ä¸ arguments.length æ¯ function å
§é¨çç©ä»¶ï¼ææä¾çæ£å³é² function ä¸ç忏æ¸éã
Function 建æ§åç data property
Function 建æ§åæ¬èº«å°±æ¯ä¸å Function ç©ä»¶ãå
¶ length data property çå¼çº 1ãæ¤ property ç attributes å
å«: Writable: false, Enumerable: false, Configurable: true.
Function prototype ç©ä»¶ç property
Function prototype ç©ä»¶ç length property å
¶å¼çº 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, rest parameter ä¸å
å«å¨å
§ */
console.log(function (a, b = 1, c) {}.length); /* 1 */
// åªæå¨é è¨åæ¸åç忏æè¢«ç®å°ï¼ä¹å°±æ¯åªæ a æè¢«è¦çºå¿
é å³å
¥ç忏
// è c å°è¢«é è¨çº undefined
è¦ç¯
| Specification |
|---|
| ECMAScript® 2027 Language Specification> # sec-function-instances-length> |