Created
December 28, 2018 02:27
-
-
Save jackyshan/8e5edeb53b23664388850b9efe1caf81 to your computer and use it in GitHub Desktop.
js实现promise,async,await
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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