Function對象的length屬性用于返回該函數定義的參數個數。
該屬性屬于Function對象,所有主流瀏覽器均支持該屬性。
## 語法
```
functionObject.length
```
## 返回值
length屬性的值為Number類型,返回當前函數在定義時聲明的參數個數。
當創建一個函數的實例時,函數的length屬性由JavaScript引擎初始化為該函數定義中的參數數目。
## 示例&說明
```
function test(){
document.writeln("本函數定義的參數個數為" + test.length);
};
test(); // 本函數定義的參數個數為0
function foo(a, b){
document.writeln("本函數定義的參數個數為" + foo.length);
};
foo(1, 2); // 本函數定義的參數個數為2
function bar(a, b, c, d){
document.writeln("本函數定義的參數個數為" + bar.length);
}
// length屬性只與定義函數時的參數個數有關,與調用時傳入的參數個數無關
bar(); // 本函數定義的參數個數為4
// 也可在函數外部直接調用
document.write(foo.length); // 2
```