回答編集履歴
1
追記
answer
CHANGED
@@ -35,4 +35,42 @@
|
|
35
35
|
</html>
|
36
36
|
```
|
37
37
|
|
38
|
-
なお [[JavaScript] prototypeに直接代入しちゃうのってダメじゃなかったっけ?](http://liosk.blog103.fc2.com/blog-entry-193.html)
|
38
|
+
なお [[JavaScript] prototypeに直接代入しちゃうのってダメじゃなかったっけ?](http://liosk.blog103.fc2.com/blog-entry-193.html)
|
39
|
+
|
40
|
+
追記
|
41
|
+
|
42
|
+
このようにしたらできました。
|
43
|
+
スクリプトが実行される時点でまだ body が読み込まれていなかったからでしょう。
|
44
|
+
なお、上記リンクを読んでおいてください。
|
45
|
+
|
46
|
+
```JavaScript
|
47
|
+
<!DOCTYPE html>
|
48
|
+
<html lang="ja">
|
49
|
+
|
50
|
+
<head>
|
51
|
+
<meta charset="utf-8" />
|
52
|
+
<title>試行</title>
|
53
|
+
</head>
|
54
|
+
|
55
|
+
<body id="test">
|
56
|
+
<script>
|
57
|
+
const _d = document;
|
58
|
+
|
59
|
+
const Hoge = function () {
|
60
|
+
alert("実験成功 : 最終更新日時は" + _d.lastModified);
|
61
|
+
}
|
62
|
+
|
63
|
+
Hoge.prototype = {
|
64
|
+
testdesuyo: function () {
|
65
|
+
alert("実験成功 : 最終更新日時は" + _d.lastModified);
|
66
|
+
_d.getElementById("test").insertAdjacentHTML('afterbegin', '<p>testes</p>');
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
let hoge = new Hoge();
|
71
|
+
hoge.testdesuyo();
|
72
|
+
</script>
|
73
|
+
</body>
|
74
|
+
|
75
|
+
</html>
|
76
|
+
```
|