123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263 |
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <title>Document</title>
- </head>
- <body>
- <script>
- /**
- * 1、replaceAll
- */
- const str = 'hello world';
- str.replaceAll('l', ''); // "heo word"
- /**
- * 2、Promise.any
- * 若有成功,返回其中一个成功的,若都不成功,则返回All promises were rejected
- * es11中Promise.allSettled 无论成功失败都返回,并有状态
- */
- const promise1 = new Promise((resolve, reject) => resolve('我是成功的Promise_1'));
- const promise2 = new Promise((resolve, reject) => resolve('我是失败的Promise_2'));
- const promiseList = [promise1, promise2];
- Promise.any(promiseList)
- .then(values=>{
- console.log(values); //AggregateError: All promises were rejected
- }).catch(e=>{
- console.log(e);
- });
- /**
- * 3、WeakRefs
- * 使用WeakRefs的Class类创建对对象的弱引用(对对象的弱引用是指当该对象应该被GC回收时不会阻止GC的回收行为)
- */
-
- /**
- * 4、运算逻辑符和赋值表达式
- */
- // a ||= b
- // //等价于
- // a = a || (a = b) //取第一个真值,都是假时返回最后一个值
- // a &&= b
- // //等价于
- // a = a && (a = b) //第一个真值,返回第二个,第一个假值,直接返回假值,都是真时,返回最后一个
- // a ??= b
- // //等价于
- // a = a ?? (a = b)
- let a = 1
- let b = 2
- console.log(a ?? (a=b))
- /**
- * 5、数字分割符
- */
- const money = 1_000_000_000;
- //等价于
- const money1 = 1000000000;
- console.log(1_000_000_000 === 1000000000); // true
- </script>
- </body>
- </html>
|