首页 > 其他分享 >js async await

js async await

时间:2022-10-27 12:15:04浏览次数:38  
标签:function await js promise 返回值 async foo

async 函数一定会返回一个 promise 对象。如果一个 async 函数的返回值看起来不是 promise,那么它将会被隐式地包装在一个 promise 中。
如
async function foo() {
  return 1;
}
等价于
function foo() {
  return Promise.resolve(1);
}

在 await 表达式之后的代码可以被认为是存在在链式调用的 then 回调中,多个 await 表达式都将加入链式调用的 then 回调中,返回值将作为最后一个 then 回调的返回值。

标签:function,await,js,promise,返回值,async,foo
From: https://www.cnblogs.com/sqmw/p/16831762.html

相关文章

  • Node.JS 安装(Windows 和 Linux )
    1、Linux版采用YUM方式安装。1.1、卸载旧版本查看旧版本:rpm-qa|grepnodejs卸载:卸载过程中输入y确认yumremovenodejs1.2、安装1.2.1、Hint官......
  • 打印的js
    //打印类属性、方法定义/*eslint-disable*/constPrint=function(dom,options){if(!(thisinstanceofPrint))returnnewPrint(dom,options);this.op......
  • 项目实战:在线报价采购系统(React +SpreadJS+Echarts)
    小伙伴们对采购系统肯定不陌生,小到出差路费、部门物资采购;大到生产计划、原料成本预估都会涉及到该系统。管理人员可以通过采购系统减少管理成本,说是管理利器毫不过分,对于......
  • PHP json_decode如何输出数组(php json_decode how to output array)
    Hereismyphpcodewithjsonformattedstring:$string=';?>Iwanttolearnhowtoparse/outputjsonstringintosomethingIcanshowinhtmlorput......
  • openlayers 添加行政区域 geojson
    先地图初始化然后再添加图层 import{VectorasVectorLayer}from'ol/layer';import{VectorasVectorSource}from'ol/source';import{GeoJSON}from'ol......
  • 配置 tsconfig.json
    tsconfig.json所包含的属性并不多,只有7个,ms官方也给出了它的定义文件。但看起来并不怎么舒服,这里就翻译整理一下。(若有误,还请指出)files:数组类型,用于表示由ts管理......
  • mytime.js 时间的常用计算,配合使用
    //获得本周的开始日期functiongetWeekStartDate(){letweekStartDate=newDate(newDate().getFullYear(),newDate().......
  • js 导出excle文件(多页)
     --前提:页面生成相应的表格数据  例如:<tableid="a"> <tr> <th></th> </tr> <tr> <td></td> </tr> </t......
  • 删除 设置 获取 cookies 的第三方包 js-cookies
    //第三方包js-cookies是一个操作cookies的包importCookiesfrom'js-cookie'//Cookies.set(key,value)存值//Cookies.get(key)取值//Cookies.remove(key)......
  • ReactJS单页面应用之项目搭建
    初衷因接手的项目前端采用reactjs+antd,为把控项目中的各个细节,所以想做一些整理,以免后期遗忘。创建及启动项目#全局安装create-react-app#如果曾经安装过,可先移除:n......