回答編集履歴
2
FileList.prototype.length
answer
CHANGED
@@ -19,6 +19,40 @@
|
|
19
19
|
</script>
|
20
20
|
```
|
21
21
|
|
22
|
+
### FileList.prototype.length
|
23
|
+
|
24
|
+
FileList InterfaceのIDLは下記の通り。
|
25
|
+
|
26
|
+
- [5. FileList インタフェース - File API (日本語訳)](https://triple-underscore.github.io/File_API-ja.html#filelist-section)
|
27
|
+
|
28
|
+
> ```
|
29
|
+
> [Exposed=(Window,Worker), Serializable]
|
30
|
+
> interface FileList {
|
31
|
+
> getter File? item(unsigned long index);
|
32
|
+
> readonly attribute unsigned long length;
|
33
|
+
> };
|
34
|
+
> ```
|
35
|
+
|
36
|
+
Google Chromeでも `FileList.prototype.length` に getter が定義されていることを確認できます。
|
37
|
+
|
38
|
+
- [Object.prototype.hasOwnProperty() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/hasOwnProperty)
|
39
|
+
- [Object.getOwnPropertyDescriptor() - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Object/getOwnPropertyDescriptor)
|
40
|
+
|
41
|
+
```HTML
|
42
|
+
<input id="sample" type="file">
|
43
|
+
|
44
|
+
<script>
|
45
|
+
'use strict';
|
46
|
+
const files = document.getElementById('sample').files;
|
47
|
+
const filesPrototype = Object.getPrototypeOf(files);
|
48
|
+
|
49
|
+
console.log(filesPrototype === FileList.prototype); // true
|
50
|
+
console.log(files.hasOwnProperty('length')); // false
|
51
|
+
console.log(filesPrototype.hasOwnProperty('length')); // true
|
52
|
+
console.log(Object.getOwnPropertyDescriptor(filesPrototype, 'length')); // {set: undefined, enumerable: true, configurable: true, get: ƒ}
|
53
|
+
</script>
|
54
|
+
```
|
55
|
+
|
22
56
|
### プロトタイプチェーン
|
23
57
|
|
24
58
|
前述のコードの理解が難しいようでしたら、「プロトタイプチェーン」を調べてみてください。
|
1
FileList -> FileList.prototype
answer
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
### HTMLInputElement.prototype.files
|
2
2
|
|
3
|
-
`HTMLInputElement.prototype.files` を参照すれば、「`FileList` を `[[Prototype]]` に持つオブジェクト」を返します。
|
3
|
+
`HTMLInputElement.prototype.files` を参照すれば、「`FileList.prototype` を `[[Prototype]]` に持つオブジェクト」を返します。
|
4
4
|
|
5
5
|
- [HTMLInputElement - Web API | MDN](https://developer.mozilla.org/ja/docs/Web/API/HTMLInputElement)
|
6
6
|
- [FileList - Web API | MDN](https://developer.mozilla.org/ja/docs/Web/API/FileList)
|