回答編集履歴
1
Element.prototype.innerHTML
answer
CHANGED
@@ -33,4 +33,36 @@
|
|
33
33
|
|
34
34
|
> interface は、その宣言の波括弧を成す合間に現れる,一連のメンバが成す集合( InterfaceMembers に合致)の仕様である。 これらのメンバは、 **interface メンバ** と称される。
|
35
35
|
|
36
|
+
### Element.prototype.innerHTML
|
37
|
+
|
38
|
+
`innerHTML` は **interface Element** に属するIDL属性です。
|
39
|
+
仕様としては下記URLのIDLに記載があります。
|
40
|
+
|
41
|
+
- [2.3. Element インタフェースに対する拡張 - DOM Parsing and Serialization (日本語訳)](https://triple-underscore.github.io/DOM-Parsing-ja.html#extensions-to-the-element-interface)
|
42
|
+
|
43
|
+
> ```plain
|
44
|
+
> partial interface Element {
|
45
|
+
> [CEReactions, TreatNullAs=EmptyString] attribute DOMString innerHTML;
|
46
|
+
> };
|
47
|
+
> ```
|
48
|
+
|
49
|
+
JavaScript としては `Element.prototype.innerHTML` にプロパティ(メソッドではない)が存在する事になります。
|
50
|
+
|
51
|
+
```JavaScript
|
52
|
+
console.log(Element.prototype.hasOwnProperty('innerHTML')); // true
|
53
|
+
```
|
54
|
+
|
55
|
+
Elementとは DOM Interface Objectの一種であり、DOM上でいう**要素ノード**は必ず、Element が [[Prototype]] 上に存在します。
|
56
|
+
|
57
|
+
```JavaScript
|
58
|
+
var p = document.createElement('p');
|
59
|
+
console.log(p.__proto__ === HTMLParagraphElement.prototype); // true
|
60
|
+
console.log(p.__proto__.__proto__ === HTMLElement.prototype); // true
|
61
|
+
console.log(p.__proto__.__proto__.__proto__ === Element.prototype); // true
|
62
|
+
```
|
63
|
+
|
64
|
+
このように、**プロトタイプチェーン(prototype-chain)**の仕組みによって上位プロトタイプに `Element.prototype` が存在する為、変数 p は innerHTML を使用できる状態となっています。
|
65
|
+
|
66
|
+
- [継承とプロトタイプチェーン - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain)
|
67
|
+
|
36
68
|
Re: yamagata_user さん
|