当前位置: 首页 > news >正文

建设公司招聘关键词优化包含

建设公司招聘,关键词优化包含,seo服务标准,武汉万网站制作 费用背景 背景就是遇到了一个比较烦人的模块,里面的涉及到了大量的async 和 awiat。发现大多人对这个语法糖一知半解,然后大量的滥用,整理一下 async 前置知识: Promise.resolve(foo) new Promise(resolve > resolve(foo)…

背景

背景就是遇到了一个比较烦人的模块,里面的涉及到了大量的async 和 awiat。发现大多人对这个语法糖一知半解,然后大量的滥用,整理一下

async

前置知识:

 Promise.resolve('foo)   ===    new Promise(resolve => resolve('foo'))Promise.reject('foo)    ===  new Promise((resolve, reject) => reject('出错了'))

1、async修饰的函数返回一个promise

async function myName() {let result = await Promise.resolve("hello")let result1 =  await Promise.resolve("hello1")console.log(result)console.log(result1)
}
myName().then(e => console.log(e))
//hello
//hello1
//undefined (函数没有返回任何的值所以是undefined)---------------------
async function myName() {let result = await Promise.resolve("hello")let result1 =  await Promise.resolve("hello1")return ({result,result1})
}
myName().then(e => console.log(e))
// { result: 'hello', result1: 'hello1' }

2、注意以下用法,以下用法在项目中使用是极多的

i:以下的这种写法就很好理解了,没问题的

function timeout(ms) {return new Promise((resolve) => {setTimeout(resolve, ms);});
}
async function asyncPrint(value, ms) {await timeout(ms);console.log(value);
}asyncPrint('hello world', 50)
// hello world

ii:因为async返回一个promise,所以下述写法完全等同于i的写法

async function timeout(ms) {await new Promise((resolve) => {setTimeout(resolve, ms);});
}
async function asyncPrint(value, ms) {await timeout(ms);console.log(value);
}
asyncPrint('hello world', 50)
// hello world

在这里插入图片描述

async function timeout(ms) {await new Promise((resolve) => {setTimeout(resolve, ms);});console.log(8888)
}
async function asyncPrint(value, ms) {let res =  timeout(ms)console.log(res) console.log(value);
}
asyncPrint('hello world', 50)
// Promise { <pending> }
// hello world
// 8888
async function timeout(ms) {await new Promise((resolve) => {setTimeout(resolve, ms);});console.log(8888)
}async function asyncPrint(value, ms) {let res =  timeout(ms)console.log(res) await timeout(ms);console.log(value);
}
asyncPrint('hello world', 50)
//Promise { <pending> }
// 8888
// 8888
// hello world

await

await修饰异步,在async中使用,当promise是resolve时接着往下走

1、awiat(直接用),只能接收resolve返回的参数

async function myName() {let result = await Promise.resolve("hello")let result1 = await Promise.resolve("hello1")console.log(result)console.log(result1)
}
myName()
// hello
// hello1
async function myName1() {let result = await Promise.reject("hello")console.log(result)
}
myName1()
// 报错了
------------
async function myName1() {let result = await Promise.reject("hello")console.log(111111111111111)console.log(result)
}
myName1()
// 报错了(console都没走)

2、搭配 try catch 可以用 catch捕捉到reject的错误

async function myName2() {try {let result = await Promise.reject("hello")console.log(result)} catch (error) {console.log('出错了',error)}
}
myName2()
// 出错了 hello

3、try catch ,try内之要有一个promise reject,那么后续的就都不会进行了,直接将第一个reject给catch给出去了

async function myName2() {try {let result = await Promise.reject("hello")console.log(result)let result1 = await Promise.resolve("hello word")console.log(result1)} catch (error) {console.log('出错了',error)}
}
myName2()
// 出错了 hello
----------------------------------------
// 下方demo为了证明,报错后没有再往后走
async function myName2() {try {await Promise.reject("hello")console.log('走不走')let result1 = await Promise.resolve("hello word")console.log(result1)} catch (error) {console.log('出错了',error)}
}
myName2()
// 出错了 hello

   function name() {try {throw new Error('出错了');console.log(1111);} catch (e) {console.log(e);}}

如果抛出错误 throw new Error 就不在往下走了,不会执行执行打印,走到了catch

    async onSubmit() {this.lastClickEvent = this.CLICK_EVENT.ADD;try {await this.commonAdd();this.$message({type: 'success',message: this.$t('msg_success')});if (this.isClient) {this.SynchronizeResourceUpdate();}if (!this.accessGuide) {this.back();}} catch (error) {console.log(error);}},

commonAdd如果有throw new Error也就不往下走了,try catch被中断

await 结果接收

await将结果赋值,只能在正确(resolve)的时候处理

async function ll() {let w = await Promise.resolve('出错了');console.log(w);let y = await Promise.resolve('hello');console.log(y);
}
ll();
// 出错了
// hello
async function ll() {let w = await Promise.reject('出错了');console.log(w);let y = await Promise.reject('hello');console.log(y);
}
ll(); 
// Promise {<rejected>: "出错了"}
http://www.hengruixuexiao.com/news/19073.html

相关文章:

  • 唐山cms模板建站西安seo代理
  • 如何做快递api接口网站如何做网站推广及优化
  • dns解析失败登录不了网站前端seo怎么优化
  • 关于推进公司网站开发的请示网站源码
  • 做视频最全的网站百度竞价开户费用
  • 做自己任务的网站新浪体育nba
  • 怎么添加网站权重石家庄网站优化
  • 移动网站建设服务商小学生简短小新闻
  • 755权限 wordpress中山seo推广优化
  • 电脑编程培训seo推广编辑
  • 唐山做网站哪家公司好西安做网站的网络公司
  • 不会编程怎么做网站seo关键词选取工具
  • 网站收藏的链接怎么做的萌新seo
  • 成都市建设厅网站扬州百度推广公司
  • 新疆的小网站seo优化实训报告
  • 网站是怎么优化推广的整合营销传播方案案例
  • 漳州模板网站建设教育培训机构加盟
  • 做网站挣钱吗网络营销与直播电商
  • 手机笑话网站模板如何做免费网络推广
  • 怎么做阿里巴巴网站百度自然排名优化
  • 网站seo怎样做营销推广
  • webview做网站app个人如何在百度做广告
  • 男生和男生做污的视频网站一句简短走心文案
  • 想学网站搭建与推广找资源
  • 小程序推广模式和营销方案培训seo去哪家机构最好
  • 第三方网站建设平台百度官方人工客服电话
  • 建设个人网站需要什么条件网络推广什么做
  • 汕头模板建站软件如何进行关键词分析
  • 中国核工业建设集团公司seo实战优化
  • ui设计师面试seo赚钱项目