回答編集履歴
1
追記
answer
CHANGED
@@ -36,4 +36,26 @@
|
|
36
36
|
*/
|
37
37
|
console.log( a.b.c.data )
|
38
38
|
// => {sample: "SAMPLE"}
|
39
|
+
```
|
40
|
+
追記)
|
41
|
+
|
42
|
+
fetch の遅延を考える
|
43
|
+
|
44
|
+
```javascript
|
45
|
+
/* omitted */
|
46
|
+
fetchData() {
|
47
|
+
fetch('sample.json')
|
48
|
+
.then(res => res.json())
|
49
|
+
.then( json => {
|
50
|
+
this.data = json;
|
51
|
+
if( "function" === typeof this.onload ) {
|
52
|
+
this.onload(this);
|
53
|
+
}
|
54
|
+
})
|
55
|
+
}
|
56
|
+
/* omitted */
|
57
|
+
const a = new A();
|
58
|
+
a.b.c.onload = function(c){
|
59
|
+
alert(JSON.stringify(c.data));
|
60
|
+
}
|
39
61
|
```
|