回答編集履歴
2
FileList.prototype.length
test
CHANGED
@@ -40,6 +40,74 @@
|
|
40
40
|
|
41
41
|
|
42
42
|
|
43
|
+
### FileList.prototype.length
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
FileList InterfaceのIDLは下記の通り。
|
48
|
+
|
49
|
+
|
50
|
+
|
51
|
+
- [5. FileList インタフェース - File API (日本語訳)](https://triple-underscore.github.io/File_API-ja.html#filelist-section)
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
> ```
|
56
|
+
|
57
|
+
> [Exposed=(Window,Worker), Serializable]
|
58
|
+
|
59
|
+
> interface FileList {
|
60
|
+
|
61
|
+
> getter File? item(unsigned long index);
|
62
|
+
|
63
|
+
> readonly attribute unsigned long length;
|
64
|
+
|
65
|
+
> };
|
66
|
+
|
67
|
+
> ```
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
Google Chromeでも `FileList.prototype.length` に getter が定義されていることを確認できます。
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
- [Object.prototype.hasOwnProperty() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
|
76
|
+
|
77
|
+
- [Object.getOwnPropertyDescriptor() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
```HTML
|
82
|
+
|
83
|
+
<input id="sample" type="file">
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
<script>
|
88
|
+
|
89
|
+
'use strict';
|
90
|
+
|
91
|
+
const files = document.getElementById('sample').files;
|
92
|
+
|
93
|
+
const filesPrototype = Object.getPrototypeOf(files);
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
console.log(filesPrototype === FileList.prototype); // true
|
98
|
+
|
99
|
+
console.log(files.hasOwnProperty('length')); // false
|
100
|
+
|
101
|
+
console.log(filesPrototype.hasOwnProperty('length')); // true
|
102
|
+
|
103
|
+
console.log(Object.getOwnPropertyDescriptor(filesPrototype, 'length')); // {set: undefined, enumerable: true, configurable: true, get: ƒ}
|
104
|
+
|
105
|
+
</script>
|
106
|
+
|
107
|
+
```
|
108
|
+
|
109
|
+
|
110
|
+
|
43
111
|
### プロトタイプチェーン
|
44
112
|
|
45
113
|
|
1
FileList -> FileList.prototype
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
|
4
4
|
|
5
|
-
`HTMLInputElement.prototype.files` を参照すれば、「`FileList` を `[[Prototype]]` に持つオブジェクト」を返します。
|
5
|
+
`HTMLInputElement.prototype.files` を参照すれば、「`FileList.prototype` を `[[Prototype]]` に持つオブジェクト」を返します。
|
6
6
|
|
7
7
|
|
8
8
|
|