es6中 async await 底层实现原理
Input async function findPosts() { var response = await $.get('/posts'); return JSON.parse(response.posts); } async function main() { console.log('starting...'); var posts = await findPosts(); posts.forEach(function (post) { console.log(post); }); console.log('ending...'); } main(); Output function findPosts() { var ctx = this, args = arguments; return Promise.resolve().then(function () { var response; return $.get('/posts').then(function (value) { response = value; return JSON.parse(response.posts); }); }); } function main() { var ctx = this, args = arguments; return Promise.resolve().then