javascript async code: callback function、Eventlistener、 Promise、Generator、async/await
JS handle async code: callback function、Eventlistener、 Promise、Generator、async/await。 callback----------- 1.ajax; 2.setTimeout; 3.Eventlistener; 4.Nodejs method; Promise------------- Promise 1 way function read(url){ return new Promise((resolve,reject)=>{ fs.readFile(url, 'utf8', (err,data)=>{ if(err) reject(err); resolve(data); }); }); } read(A).then(data=>{return read(B);}) .then(data=>{return read(C);}) .then(data=>{return read(D);}) .catch(reason=>{console.log(reason);}); //Promis.all---------- Promise.all([read(A),read(B),read(C)]) .then(data=>{console.log(data);}) .catch(err=>console.log(err) ); Generator----------------------yield-------------- function* gen(){ let a=yield 111; console.log(a); let b=yield 222; console.log(b); let c=yield 333; console.log(c); let d=yield 444; console.log(d); } l...