aboutsummaryrefslogtreecommitdiff
path: root/files/zh-tw/web/javascript/reference/global_objects/function/length/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/zh-tw/web/javascript/reference/global_objects/function/length/index.html')
-rw-r--r--files/zh-tw/web/javascript/reference/global_objects/function/length/index.html144
1 files changed, 144 insertions, 0 deletions
diff --git a/files/zh-tw/web/javascript/reference/global_objects/function/length/index.html b/files/zh-tw/web/javascript/reference/global_objects/function/length/index.html
new file mode 100644
index 0000000000..699e1ff178
--- /dev/null
+++ b/files/zh-tw/web/javascript/reference/global_objects/function/length/index.html
@@ -0,0 +1,144 @@
+---
+title: Function.length
+slug: Web/JavaScript/Reference/Global_Objects/Function/length
+translation_of: Web/JavaScript/Reference/Global_Objects/Function/length
+---
+<div>{{JSRef}}</div>
+
+<p><code><strong>length</strong></code> property表示該 function 預期被傳入的參數數量</p>
+
+<div>{{js_property_attributes(0,0,1)}}</div>
+
+<h2 id="描述">描述</h2>
+
+<p><code>length</code> 是 function 物件的一個 property,表示該 function 預期被傳入的參數數量,這個數量並不包含 {{jsxref("rest_parameters", "rest parameter", "", 1)}} 且只包涵第一個預設參數(Default Parameters)前的參數。相較之下 {{jsxref("Functions_and_function_scope/arguments/length", "arguments.length")}} 是 function 內部的物件,會提供真正傳進 function 中的參數數量。</p>
+
+<h3 id="Function_建構子的_data_property"><code>Function</code> 建構子的 data property</h3>
+
+<p>{{jsxref("Function")}} 建構子本身就是一個 {{jsxref("Function")}} 物件。其 <code>length</code> data property 的值為 1。此 property 的 attributes 包含: Writable: <code>false</code>, Enumerable: <code>false</code>, Configurable: <code>true</code>.</p>
+
+<h3 id="Function_prototype_物件的_property"><code>Function</code> prototype 物件的 property</h3>
+
+<p>{{jsxref("Function")}} prototype 物件的 length property 其值為 0。</p>
+
+<h2 id="範例">範例</h2>
+
+<pre class="brush: 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
+</pre>
+
+<h2 id="規範">規範</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">規範</th>
+ <th scope="col">狀態</th>
+ <th scope="col">註釋</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES1')}}</td>
+ <td>{{Spec2('ES1')}}</td>
+ <td>最初的定義,在 JavaScript 1.1 中實作。</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES5.1', '#sec-15.3.5.1', 'Function.length')}}</td>
+ <td>{{Spec2('ES5.1')}}</td>
+ <td> </td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ES6', '#sec-function-instances-length', 'Function.length')}}</td>
+ <td>{{Spec2('ES6')}}</td>
+ <td><code>此 </code>property 的 <code>configurable</code> attribute 現在為 <code>true</code>.</td>
+ </tr>
+ <tr>
+ <td>{{SpecName('ESDraft', '#sec-function-instances-length', 'Function.length')}}</td>
+ <td>{{Spec2('ESDraft')}}</td>
+ <td> </td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="瀏覽器相容性">瀏覽器相容性</h2>
+
+<div>{{CompatibilityTable}}</div>
+
+<div id="compat-desktop">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>特點</th>
+ <th>Chrome</th>
+ <th>Firefox (Gecko)</th>
+ <th>Internet Explorer</th>
+ <th>Opera</th>
+ <th>Safari</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ <tr>
+ <td>Configurable: true</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoDesktop(37)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<div id="compat-mobile">
+<table class="compat-table">
+ <tbody>
+ <tr>
+ <th>Feature</th>
+ <th>Android</th>
+ <th>Chrome for Android</th>
+ <th>Firefox Mobile (Gecko)</th>
+ <th>IE Mobile</th>
+ <th>Opera Mobile</th>
+ <th>Safari Mobile</th>
+ </tr>
+ <tr>
+ <td>Basic support</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ <td>{{CompatVersionUnknown}}</td>
+ </tr>
+ <tr>
+ <td>Configurable: true</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatGeckoMobile(37)}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ <td>{{CompatUnknown}}</td>
+ </tr>
+ </tbody>
+</table>
+</div>
+
+<h2 id="可參閱">可參閱</h2>
+
+<ul>
+ <li>{{jsxref("Function")}}</li>
+</ul>