We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
No description provided.
The text was updated successfully, but these errors were encountered:
Promise
async function fn() { console.log('Hello world!'); } console.log(fn().constructor); // Promise() // 这里证明其返回值为一个 Promise 对象;
promise对象有resolve和reject两种状态,相应的有.then()和.catch()两种方法来获取返回值
async /await 需要在function外部写async,在内部需要等待执行的函数前书写await
async function fn() { console.log(1); new Promise(function(resolve, reject) { setTimeout(function() { console.log(2); }); }); console.log(3); } fn(); 结果为: 1 3 2
await 会等到后面的 Promise 返回结果后才会执行 async 函数后面剩下的语句,也就是说如果 Promise 不返回结果(如 resolve 或 reject),后面的代码就不会执行
async function fn() { console.log(1); await new Promise(function(resolve, reject) { setTimeout(function() { console.log(2); }); }); console.log(3); } fn(); 结果为: 1 2
async function fn() { console.log(1); await new Promise(function(resolve, reject) { setTimeout(function() { console.log(2); resolve(); }); }); console.log(3); } fn(); 结果为: 1 2 3
Sorry, something went wrong.
No branches or pull requests
No description provided.
The text was updated successfully, but these errors were encountered: