mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2025-05-28 21:32:20 +00:00
Use function assign instead of function declaration inner function
在函数内定义函数推荐使用变量赋值方式代替函数声明方式
This commit is contained in:
parent
6b300cf491
commit
08a623935e
@ -118,14 +118,7 @@ function loadImageAsync(url) {
|
||||
```javascript
|
||||
const getJSON = function(url) {
|
||||
const promise = new Promise(function(resolve, reject){
|
||||
const client = new XMLHttpRequest();
|
||||
client.open("GET", url);
|
||||
client.onreadystatechange = handler;
|
||||
client.responseType = "json";
|
||||
client.setRequestHeader("Accept", "application/json");
|
||||
client.send();
|
||||
|
||||
function handler() {
|
||||
const handler = function () {
|
||||
if (this.readyState !== 4) {
|
||||
return;
|
||||
}
|
||||
@ -135,6 +128,13 @@ const getJSON = function(url) {
|
||||
reject(new Error(this.statusText));
|
||||
}
|
||||
};
|
||||
const client = new XMLHttpRequest();
|
||||
client.open("GET", url);
|
||||
client.onreadystatechange = handler;
|
||||
client.responseType = "json";
|
||||
client.setRequestHeader("Accept", "application/json");
|
||||
client.send();
|
||||
|
||||
});
|
||||
|
||||
return promise;
|
||||
|
Loading…
x
Reference in New Issue
Block a user