Movatterモバイル変換


[0]ホーム

URL:


  1. 給開發者的 Web 技術文件
  2. JavaScript
  3. JavaScript 參考文件
  4. 標準內建物件
  5. Function
  6. Function.length

此頁面由社群從英文翻譯而來。了解更多並加入 MDN Web Docs 社群。

View in EnglishAlways switch to English

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。

範例

js
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® 2026 Language Specification
# sec-function-instances-length

瀏覽器相容性

參見

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp