First, before ES6: using the original callback function, you will fall back to the region two, ES6:
1. Promise
//Click the OK button to get a list of denominations Getfaceresult () {this.getlocation (this.ph Onenum). Then (res = = (Res.status = = && res.data.success) { Let province = Res.data.obj.province; Let city = res.data.obj.city; This.getfacelist (province, city). Then (res = = {if (re S.status = = = && res.data.success) {this.facelist = Res.data.obj } }) } }) . catch (Err = {Console.log (ERR)})}
Promise's approach solves the callback hell, but this approach is full of Promise methods, and if the process is then() complicated, the entire code will be filled then . The semantics are not obvious, and the code flow does not represent the execution process well.
2. Generator
function* G () { const A = yield console.log (' A ', a) //A AAA const B = yield of console.log (' B ', b) //b bbb const C = yield console.log (' C ', c) //C Ccc}const g = g () g.next () //value:100, Done:falseg.next (' AAA ')//value:200, Done:falseg.next (' BBB ')//value:300, Done:falseg.next (' CCC ')//Value:undefin Ed, done:true.
The way of Generator solves some problems of Promise, the process is more intuitive and semantic. The problem with Generator, however, is that the execution of the function depends on the executor, and each time it needs to be executed g.next() in a way.
Third, ES7
1. async/await
Async function TestResult () {Let first = await doubleafter2seconds (); Let second = await doubleafter2seconds (a); Let third = await doubleafter2seconds (+); Console.log (first + second + third);}
asyncThe function perfectly solves the problem of the above two ways. The process is clear, intuitive and semantically explicit. Manipulating asynchronous processes is like manipulating the synchronization process. At async the same time the function comes with an actuator and does not need to be loaded manually.
Reference Link: 1190000010244279
JS asynchronous Task Processing Mode 2