js同步执行两个函数
作者:互联网
先执行test1(),再执行test2:
function test1() { return new Promise(resolve => { setTimeout(() => resolve("test1"), 2000); }); } function test2() { console.log("test2"); } async function test3() { const result = await test1(); console.log(result); test2(); } test3(); console.log('end');
输出:
> end
> test1 > test2 js在线编辑器:https://jsrun.net/new标签:test1,function,test3,test2,console,log,js,同步,函数 来源: https://www.cnblogs.com/v5captain/p/16331308.html