async function testAsync() {
return "hello async";
}
let result = testAsync();
console.log(result)
Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: "hello async"}
async function testAsync1() {
console.log("hello async");
}
let result1 = testAsync1();
console.log(result1);
hello async
Promise {[[PromiseStatus]]: "resolved", [[PromiseValue]]: undefined}
function testSometing() {
console.log("执行testSometing");
return "testSometing";
}
async function testAsync() {
console.log("执行testAsync");
return Promise.resolve("hello async");
}
async function test() {
console.log("test start...");
const v1 = await testSometing();//关键点1
console.log(v1);
const v2 = await testAsync();
console.log(v2);
console.log(v1, v2);
}
test();
var promise = new Promise((resolve)=> { console.log("promise start.."); resolve("promise");});//关键点2
promise.then((val)=> console.log(val));
console.log("test end...")
test start... 执行testSometing promise start.. test end... testSometing 执行testAsync promise hello async testSometing hello async
const v1 = await testSometing();
var promise = new Promise((resolve)=> { console.log("promise
start.."); resolve("promise");});//关键点2
const v2 = await testAsync();
async function testSometing() {
console.log("执行testSometing");
return "testSometing";
}
async function testAsync() {
console.log("执行testAsync");
return Promise.resolve("hello async");
}
async function test() {
console.log("test start...");
const v1 = await testSometing();
console.log(v1);
const v2 = await testAsync();
console.log(v2);
console.log(v1, v2);
}
test();
var promise = new Promise((resolve)=> { console.log("promise start.."); resolve("promise");});//3
promise.then((val)=> console.log(val));
console.log("test end...")
test start... 执行testSometing promise start.. test end... promise testSometing 执行testAsync hello async testSometing hello async
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有