首页 > 其他分享 >es12

es12

时间:2023-11-27 16:58:04浏览次数:24  
标签:resolve console 毫秒 Promise time es12 fn

1. Promise.any

E12 新增的 Promise 的方法

接收一个 Promise 数组,数组中如有非 Promise 项,则此项当做成功
如果有一个 Promise 成功,则返回这个成功结果
如果所有 Promise 都失败,则报错

// 当有成功的时候,返回最快那个成功
function fn(time, isResolve) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      isResolve
        ? resolve(`${time}毫秒后成功!!!`)
        : reject(`${time}毫秒后失败!!!`);
    }, time);
  });
}

Promise.any([fn(2000, true), fn(3000), fn(1000, true)]).then(
  (res) => {
    console.log(res); // 1秒后 输出  1000毫秒后成功
  },
  (err) => {
    console.log(err);
  }
);

// 当全都失败时
function fn(time, isResolve) {
  return new Promise((resolve, reject) => {
    setTimeout(() => {
      isResolve
        ? resolve(`${time}毫秒后成功!!!`)
        : reject(`${time}毫秒后失败!!!`);
    }, time);
  });
}

Promise.any([fn(2000), fn(3000), fn(1000)]).then(
  (res) => {
    console.log(res);
  },
  (err) => {
    console.log(err); // 3秒后 报错 all Error
  }
);

2. 数字分隔符

数字分隔符可以让在定义长数字时,更加地一目了然

const num = 1000000000;

// 使用数字分隔符
const num = 1_000_000_000;

3. ||= 和 &&=

或等于(||=)   a ||= b 等同于 a || (a = b);
且等于(&&=)   a &&= b 等同于 a && (a = b);

4. 对象动态属性

经常碰到这样的问题,无论是在微信小程序还是 React 中,需要根据某个条件去修改某个数据

if (type === "boy") {
  this.setData({
    boyName: name,
  });
} else if (type === "girl") {
  this.setData({
    girlName: name,
  });
}

也不知道这个新特性叫啥,就取名叫属性动态属性

this.setData({
  [`${type}Name`]: name,
});

标签:resolve,console,毫秒,Promise,time,es12,fn
From: https://www.cnblogs.com/wp-leonard/p/17859747.html

相关文章

  • SLES12sp4安装软件
    像SLES这样的商业版系统,其实是很依赖初始安装镜像的,我也是后来才知道这件事情,要不然也不会在之前格式化安装镜像的U盘了。为什么这么说的,因为商业版系统它不是Ubuntu,如果没有订阅码的话,软件源就只能依赖初始镜像。新系统的yast里面很多功能都是未安装的,至少在我这里没装上,我又把......
  • SLES12sp4连接网络心得
    我在单位有一台安装了SLES12sp4的电脑,我一直想给它连个网,然而单位不提供网口,我只好从无线连接的方向下功夫。然而这个系统的核心版本较低,不支持市面上的无线网卡,至少不能免驱,没有网络就不能下载驱动,而且我对于linux下的软件依赖包安装一直是很恐惧的,所以此事就搁置了很长时间,直到......
  • ES7-ES12
    ES6是JavaScript的一次重大升级,但随后的版本也带来了许多新特性和改进。下面是ES6之后的几个版本的重要特性:ES2016(ES7):指数运算符(**):引入了指数运算符,用于计算乘方。Array.prototype.includes():提供了一种更简洁的方法来判断数组中是否包含某个元素。ES2017(E......
  • codeforces1283F
    题目链接sol:根一定是第一个,然后不太会,去看了洛谷题解题解#include<bits/stdc++.h>usingnamespacestd;typedeflonglongll;typedefpair<int,int>pii;#definefifirst#definesesecond#definefz1(i,n)for((i)=1;(i)<=(n);(i)++)#definefd1(i,n)for((i)......
  • ubuntu22.4.1 部署Postgres12 、PostGIS、TimescaleDB
    参考文章https://www.postgresql.org/download/linux/ubuntu/一、postgres数据库安装#Createthefilerepositoryconfiguration:1.sudosh-c'echo"debhttp://apt.postgresql.org/pub/repos/apt$(lsb_release-cs)-pgdgmain">/etc/apt/sources.list.d/pgdg.l......
  • SUSE SLES12 Security Update: libtasn1 Vulnerability_Day 10
    今天要跟大家分享的是关于SUSELinux的系统缺陷。这是一个远程SuseLinux主机缺少安全补丁的更新。下面是关于这个问题的具体的描述:TheremoteSUSELinuxSLES12hosthas......
  • Codeforces1260 E Tournament(贪心)
    Description:Youareorganizingaboxingtournament,wherenboxerswillparticipate(ispowerof),andyourfriendisoneofthem.Allboxershavedifferents......
  • Codeforces1201 B Maximum Median (二分)
    Description:Youaregivenanarray aa of nn integers,where nn isodd.Youcanmakethefollowingoperationwithit:Chooseoneoftheelementsofthearray......
  • Base64(AES128(字段,秘钥))对称加密
     代码实现如下:publicclassSecurityAESUtils{privatestaticStringAES_KEY="123456789qazwsx#";privatestaticStringAES_MODE="AES/ECB/PKCS5Pa......