当前位置:网站首页>ES7/ES9 -- 新特性与正则
ES7/ES9 -- 新特性与正则
2022-06-25 21:50:00 【攀登程序猿】
ES7新特性
检查数组中是否包含某个元素 includes 2**10 2的10次方
let array = ['红楼梦','西游记','三国演义','水浒传']
console.log(array.includes('红楼梦')) // true
console.log(array.indexOf('红楼梦')) // 0
console.log(2**10) // 1024 2的10次方ES9 正则拓展
(1)正则分组
如下图所示,可以看到明显的正则分组,并且可以将匹配到的值重新命名,使用属性的方式去获取,防止了正则变化时,数字位置变化的问题
let str = '<a href="http://www.atguigu.com">尚硅谷</a>'
console.log(str)
const REG = /<a href="(?<url>.*)">(?<text>.*)<\/a>/ // 此处不能加单引号,?<name>是对匹配到的值进行重名名
let result = REG.exec(str)
console.log(result)
console.log(result.groups.url)
(2)反向断言与正向断言
添加条件,可以判断前面的是什么或者后面的是什么,防止匹配到多个

(3)dotAll
特点:.是元字符,除换行符以外的任意单个字符,ES9添加了/s可以匹配任意字符,在正则的最后添加一个/s即可
ES10 -- 对象拓展方法
对象和Map的互换

ES10 -- 字符串的trimStart()与trimEnd()
let str = ` ilove you
and you `;
console.log(str.trimStart()) //去除开始的空白
console.log(str.trimEnd()) // 去除末尾的空白ES10 -- flat与flatMap
flat可以把多维数组转换成一维数组,里面的数字是转换的深度

ES11 -- 私有属性
使用#标注私有属性即可,在类内部可以操作私有属性,在类外部是不可以的

ES11 -- String的mathAll 匹配所有
for (let v for result){
//批量提取
}
ES11 -- 可选链操作符?.
config&&config.db&&config.db.host,先判断config是否存在,然后判断config中的db是否存在,然后才获取的host,可以简写为config?.db?.host
ES11 -- 动态import
用的时候再导入,加载速度变快
btn.onclick = function () {
import('./m1.js').then(module => {
module.hello();
})
}ES11 -- BigInt类型 大整型,在数字后面加一个n即可
更大数字运算,它支持任意长度的整数,不能和普通数值进行运算,运算的结果都是BigInt
let n = 521n; let m = BigInt(521)
ES11 -- 绝对全局对象gloalThis,指向windows对象
边栏推荐
- China coated abrasive tools industry market depth analysis and development strategy consulting report 2022-2028
- How to use the find command
- Record the learning record of the exists keyword once
- Thinking while walking
- Report on development status and prospects of global and Chinese coating industry strategic planning proposal 2022-2028
- Canoe: the fifth simulation project: simulation + test
- HLS. JS: past, present and future
- 2022giao考游记
- Hard liver! Super detailed basic introduction to Matplotlib!!!
- Hotspot JVM "01" class loading, linking and initialization
猜你喜欢

2022-2028 global industrial touch screen industry research and trend analysis report

Nacos 源码分析01 代码结构

Wpewebkit debugging MSE playback

2022-2028 global vacuum jacket system industry survey and trend analysis report

聊聊Adapter模式

Eureka core ⼼ source code analysis

Talk about adapter mode

Fujilai pharmaceutical has passed the registration: the annual revenue is nearly 500million yuan. Xiangyun once illegally traded foreign exchange

2022-2028 global SiC igniter industry research and trend analysis report

2022-2028 global iridium electrode industry research and trend analysis report
随机推荐
Reasons why MySQL cannot be connected externally after installing MySQL database on ECs and Solutions
Evaluate the generalization performance of models and build integrated models using out of pocket prediction (oof)
2022-2028 global proton exchange membrane hydrogen electrolyzer industry survey and trend analysis report
Why absolute positioning overlaps
数据治理,说起来容易,做起来难
Analysis report on scale investigation and investment development suggestions of China's special equipment inspection and testing industry 2022-2028
Diagram of stack frame running process
Research and Analysis on the current situation of China's magnetic detector Market and forecast report on its development prospect (2022)
Lecture 14 of the Blue Bridge Cup -- number theory [exercises]
Analysis of gpl3.0 license software copyright dispute cases
Exclusive interview with deepmindceo hassabis: we will see a new scientific Renaissance! AI's new achievements in nuclear fusion are officially announced today
Research and Analysis on the current situation of Chinese acne drug market and forecast report on its development prospect (2022)
Relinearization in homomorphic encryption (ckks)
【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧
Zero Trust: break the passive development mode of "attack and defense" and build a "moat" for enterprise safety
How to disable the optical drive
Créer le premier site Web avec idea
[WPF] XAML code skills that can be directly used for converting CAD engineering drawings to WPF
OSPF - detailed explanation of GRE tunnel (including configuration command)
Intimacy - [comfortable exit] - final communication to reduce injury