Properti length
menentukan jumlah argumen yang diharapkan oleh fungsi.
Property attributes of Function.length |
|
---|---|
Writable | no |
Enumerable | no |
Configurable | yes |
Deskripsi
length
merupakan properti dari objek fungsi, dan mengindikasikan berapa banyak argumen yang diharapkan fungsi, mis. jumlah parameter formal. Jumlah ini mengesampingkan rest parameter. Sebaliknya, arguments.length
adalah lokal untuk fungsi dan memberikan jumlah argumen sebenarnya ke fungsi.
Properti data dari constructor Function
Construktor Function
sendiri adalah objek Function
. data properti length
bernilai 1. Properti atribut: Writable: false
, Enumerable: false
, Configurable: true
.
Properti dari Function
prototype object
Panjang properti dari prototype objek Function
bernilai 0.
Contoh
console.log(Function.length); /* 1 */ console.log((function() {}).length); /* 0 */ console.log((function(a) {}).length); /* 1 */ console.log((function(a, b) {}).length); /* 2 etc. */ console.log((function(...args) {}).length); // 0, rest parameter is not counted console.log((function(a, b = 1, c) {}).length); // 1, only parameters before the first one with // a default value is counted
Spesifikasi
Spesifikasi | Status | Comment |
---|---|---|
ECMAScript 1st Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.1. |
ECMAScript 5.1 (ECMA-262) The definition of 'Function.length' in that specification. |
Standard | |
ECMAScript 2015 (6th Edition, ECMA-262) The definition of 'Function.length' in that specification. |
Standard | The configurable attribute of this property is now true . |
ECMAScript 2017 Draft (ECMA-262) The definition of 'Function.length' in that specification. |
Draft |
Kompabilitas browser
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Configurable: true | ? | 37 (37) | ? | ? | ? |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Configurable: true | ? | ? | 37.0 (37) | ? | ? | ? |