Skip to content

Instantly share code, notes, and snippets.

@jackyshan
Created December 28, 2018 02:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jackyshan/8e5edeb53b23664388850b9efe1caf81 to your computer and use it in GitHub Desktop.
Save jackyshan/8e5edeb53b23664388850b9efe1caf81 to your computer and use it in GitHub Desktop.
js实现promise,async,await
// async function helloAsync(){
// return "helloAsync";
// }
// console.log(helloAsync()) // Promise {<resolved>: "helloAsync"}
// helloAsync().then(v=>{
// console.log(v); // helloAsync
// })
function testAwait(){
return new Promise((resolve) => {
setTimeout(function(){
console.log("testAwait");
resolve('aaaa');
}, 1000);
});
}
async function helloAsync(){
return await Promise.resolve('dddd')
// await testAwait();
// console.log(c)
// console.log("helloAsync");
}
helloAsync().then((data)=>{
console.log(data)
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment