一、 String.prototype.replaceAll
等价于replace正则中的全局匹配g
'hello world'.replace(/o/g, '_'); // hell_ w_rld'hello world'.replaceAll('o', '_'); // hell_ w_rld
二、 数字宰割符(_)
数字两头能够增加一个‘_’减少可读性,开端和结尾不能应用,不能间断应用多个,然而能够在多处应用
Number(1__000) 有效Number(100_00) 正确Number(100_00_00) 正确Number('1_1') // 只能是数字两头,字符串有效const num = 1_1num * 10 => 110
三、 逻辑运算符
增加三种运算符:??=、&&=、||=
let test = undefined // 或者nulltest = test ?? 'defaultValue' // 示意的意思是当test的值为null或者undefined时,test值为defaultValuetest = test && 'defaultValue' // test = test || 'defaultValue'新运算符test ??= 'defaultValue'test &&= 'defaultValue'test ||= 'defaultValue'
四、 Promise.any
接管Promise数组作为参数,返回合成的Promise,只有给定的Promise中有一个胜利, 那么就以这个后果作为返回值
const promises = [ ajax('1.com').then(), ajax('2.com').then(), ajax('3.com').then()]async ....try{ const ret = await Promise.any(promises) console.log('ret',ret)}catch(error) { console.log('error',error)}