回答編集履歴
1
Element.prototype.innerHTML
test
CHANGED
@@ -68,4 +68,68 @@
|
|
68
68
|
|
69
69
|
|
70
70
|
|
71
|
+
### Element.prototype.innerHTML
|
72
|
+
|
73
|
+
|
74
|
+
|
75
|
+
`innerHTML` は **interface Element** に属するIDL属性です。
|
76
|
+
|
77
|
+
仕様としては下記URLのIDLに記載があります。
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
- [2.3. Element インタフェースに対する拡張 - DOM Parsing and Serialization (日本語訳)](https://triple-underscore.github.io/DOM-Parsing-ja.html#extensions-to-the-element-interface)
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
> ```plain
|
86
|
+
|
87
|
+
> partial interface Element {
|
88
|
+
|
89
|
+
> [CEReactions, TreatNullAs=EmptyString] attribute DOMString innerHTML;
|
90
|
+
|
91
|
+
> };
|
92
|
+
|
93
|
+
> ```
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
JavaScript としては `Element.prototype.innerHTML` にプロパティ(メソッドではない)が存在する事になります。
|
98
|
+
|
99
|
+
|
100
|
+
|
101
|
+
```JavaScript
|
102
|
+
|
103
|
+
console.log(Element.prototype.hasOwnProperty('innerHTML')); // true
|
104
|
+
|
105
|
+
```
|
106
|
+
|
107
|
+
|
108
|
+
|
109
|
+
Elementとは DOM Interface Objectの一種であり、DOM上でいう**要素ノード**は必ず、Element が [[Prototype]] 上に存在します。
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
```JavaScript
|
114
|
+
|
115
|
+
var p = document.createElement('p');
|
116
|
+
|
117
|
+
console.log(p.__proto__ === HTMLParagraphElement.prototype); // true
|
118
|
+
|
119
|
+
console.log(p.__proto__.__proto__ === HTMLElement.prototype); // true
|
120
|
+
|
121
|
+
console.log(p.__proto__.__proto__.__proto__ === Element.prototype); // true
|
122
|
+
|
123
|
+
```
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
このように、**プロトタイプチェーン(prototype-chain)**の仕組みによって上位プロトタイプに `Element.prototype` が存在する為、変数 p は innerHTML を使用できる状態となっています。
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
- [継承とプロトタイプチェーン - JavaScript | MDN](https://developer.mozilla.org/ja/docs/Web/JavaScript/Guide/Inheritance_and_the_prototype_chain)
|
132
|
+
|
133
|
+
|
134
|
+
|
71
135
|
Re: yamagata_user さん
|