Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use function assign instead of function declaration inner function
在函数内定义函数推荐使用变量赋值方式代替函数声明方式
  • Loading branch information
waitingsong committed Nov 8, 2017
commit 08a623935ecc7bb35f1419a40c3f2eff98fac1de
16 changes: 8 additions & 8 deletions docs/promise.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down