取得 Function 的引數的數量
前言
由於先前的 初探 Function.toString() 的關係,Funciton:Length 直覺上會認為是回傳程式碼的字數,但事實上不是,在此把學習的過程做個紀錄。
內容
範例如下
function fun0(){} function fun1( a ){} function fun2( a , b ){} function fun3( a , b , c ){} // console.log( fun0.length );//0 console.log( fun1.length );//1 console.log( fun2.length );//2 console.log( fun3.length );//3
Funciton:Length 回傳的是引數數量,並非程式碼的字數,範例分別是分了從沒引數到3個引數的狀況。
參考資料
[ developer.mozilla.org ] Function: length