Skip to content

Commit 08a6239

Browse files
committed
Use function assign instead of function declaration inner function
在函数内定义函数推荐使用变量赋值方式代替函数声明方式
1 parent 6b300cf commit 08a6239

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

docs/promise.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,7 @@ function loadImageAsync(url) {
118118
```javascript
119119
const getJSON = function(url) {
120120
const promise = new Promise(function(resolve, reject){
121-
const client = new XMLHttpRequest();
122-
client.open("GET", url);
123-
client.onreadystatechange = handler;
124-
client.responseType = "json";
125-
client.setRequestHeader("Accept", "application/json");
126-
client.send();
127-
128-
function handler() {
121+
const handler = function () {
129122
if (this.readyState !== 4) {
130123
return;
131124
}
@@ -135,6 +128,13 @@ const getJSON = function(url) {
135128
reject(new Error(this.statusText));
136129
}
137130
};
131+
const client = new XMLHttpRequest();
132+
client.open("GET", url);
133+
client.onreadystatechange = handler;
134+
client.responseType = "json";
135+
client.setRequestHeader("Accept", "application/json");
136+
client.send();
137+
138138
});
139139

140140
return promise;

0 commit comments

Comments
 (0)