ES7和ES8新特性的总结

includes

判断是否存在数组中,存在就返回true

const NBA = ['james','kobe','curry']
console.log(NBA.includes('james')) //true

**

例如2的10次方

console.log(2 ** 10) 1024  

async

async函数的返回值为promise对象
promise对象的结果由async函数执行的返回值决定

举例

async function fn(){
  //返回一个字符串
  // return 'lsh'
  //返回的结果不是一个promise类型的对象,返回的是一个成功的promise

  //抛出错误,返回的是一个失败的promise
  // throw new Error('出错啦')

  //返回的结果如果是一个promise对象
  return new Promise((resolve,reject)=>{
    // resolve('成功的数据')
    reject('失败的数据')
  })
}

const result = fn()
console.log(result)

result.then((res)=>{
  //console.log(res)
}).catch((err)=>{
  console.log(err)
})

await

await必须写在async函数中
await右侧的表达式一般为promise对象
await返回的是promise成功的值
await的promose失败了,就会抛出异常,需要通过try...catch捕获处理

结合使用

const p = new Promise((resolve,reject)=>{
  // resolve('成功的值')
  reject('失败的值')
})

async function main(){
  try{
    let result = await p;

    console.log(result)
  } catch(e){
    console.log(e)
  }
}
main()

entries,getOwnPropertyDescriptors

声明对象

const school = {
  name:'lsh',
  age:'18',
  cities:['北京','上海']
}

entries返回一个数组

const m = new Map(Object.entries(school))
console.log(m.get('cities'))

对象属性的描述对象,可以用于深拷贝

console.log(Object.getOwnPropertyDescriptors(school))

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值