Skip to content

Commit c131e5a

Browse files
committed
es6
1 parent 549af79 commit c131e5a

145 files changed

Lines changed: 409 additions & 159 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1-js/10-es-modern/10-set-map/article.md

Lines changed: 40 additions & 63 deletions

1-js/10-es-modern/15-promise/1-promise-settimeout/solution.md renamed to 1-js/10-es-modern/11-promise/1-promise-settimeout/solution.md

1-js/10-es-modern/15-promise/1-promise-settimeout/task.md renamed to 1-js/10-es-modern/11-promise/1-promise-settimeout/task.md

Lines changed: 27 additions & 0 deletions

1-js/10-es-modern/15-promise/guest.json renamed to 1-js/10-es-modern/11-promise/2-promise-sequence/solution.view/guest.json

File renamed without changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function httpGet(url) {
2+
3+
return new Promise(function(resolve, reject) {
4+
5+
var xhr = new XMLHttpRequest();
6+
xhr.open('GET', url, true);
7+
8+
xhr.onload = function() {
9+
if (this.status == 200) {
10+
resolve(this.response);
11+
} else {
12+
var error = new Error(this.statusText);
13+
error.code = this.status;
14+
reject(error);
15+
}
16+
};
17+
18+
xhr.onerror = function() {
19+
reject(new Error("Network Error"));
20+
};
21+
22+
xhr.send();
23+
});
24+
25+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<!doctype html>
2+
<html>
3+
<head>
4+
<meta charset="UTF-8">
5+
</head>
6+
<body>
7+
8+
<script src="httpGet.js"></script>
9+
10+
<script>
11+
'use strict';
12+
13+
let urls = ['guest.json', 'user.json'];
14+
15+
let chain = Promise.resolve();
16+
17+
let results = [];
18+
19+
urls.forEach(function(url) {
20+
chain = chain
21+
.then(() => httpGet(url))
22+
.then((result) => {
23+
results.push(result);
24+
});
25+
});
26+
27+
chain.then(() => {
28+
alert(results);
29+
});
30+
31+
</script>
32+
33+
</body>
34+
</html>

1-js/10-es-modern/15-promise/user.json renamed to 1-js/10-es-modern/11-promise/2-promise-sequence/solution.view/user.json

File renamed without changes.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "guest",
3+
"isAdmin": false
4+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
function httpGet(url) {
2+
3+
return new Promise(function(resolve, reject) {
4+
5+
var xhr = new XMLHttpRequest();
6+
xhr.open('GET', url, true);
7+
8+
xhr.onload = function() {
9+
if (this.status == 200) {
10+
resolve(this.response);
11+
} else {
12+
var error = new Error(this.statusText);
13+
error.code = this.status;
14+
reject(error);
15+
}
16+
};
17+
18+
xhr.onerror = function() {
19+
reject(new Error("Network Error"));
20+
};
21+
22+
xhr.send();
23+
});
24+
25+
}

0 commit comments

Comments
 (0)