当前位置:网站首页>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对象
边栏推荐
- Open source optimized VVC encoder in general scenarios
- Beyond natural motion: exploring the discontinuity of video interpolation
- Raspberry PI (bullseye) replacement method of Alibaba cloud source
- AbstractFactory Abstract Factory
- Basic concepts of processor scheduling
- 2022-2028 global web and browser isolation platform industry research and trend analysis report
- Relinearization in homomorphic encryption (ckks)
- MATLAB Programming Notes
- Dialog+: Audio dialogue enhancement technology based on deep learning
- How to use the find command
猜你喜欢

Openwrt (VIII) application layer development

民航局:到 2025 年我国将初步建成安全、智慧、高效和绿色的航空物流体系
Data annotation in the second half: growth flywheel under PLG mode Manfu Technology

【WPF】CAD工程图纸转WPF可直接使用的xaml代码技巧

Record the learning record of the exists keyword once
This 110 year old "longevity" enterprise has been planning for the next century

Zhihu Gaozan: what ability is important, but most people don't have it?

Cvpr2022 tutorial | machine learning remote sensing processing: agriculture and food security, University of Maryland

Programmer weekly (issue 4): the wealth view of programmers
What are the debugging methods for nodejs
随机推荐
Why can't the mobile phone be used and the computer be connected
Jz-064- maximum value of sliding window
How to guarantee idempotency of message queue
Obsidian基础教程
Intimacy - [comfortable exit] - final communication to reduce injury
A3.ansible production practice case -- system initialization roles
Obsidian basic tutorial
2022-2028 global horizontal reciprocating compressor industry research and trend analysis report
聊聊Adapter模式
NRM source switching tool
HotSpot JVM 「01」类加载、链接和初始化
2022-2028 global selective laser sintering service industry research and trend analysis report
Application runtime layotto enters CNCF cloud native panorama
Analysis report on scale investigation and investment development suggestions of China's special equipment inspection and testing industry 2022-2028
Programmer weekly (issue 4): the wealth view of programmers
HLS. JS: past, present and future
Canoe: the fifth simulation project: simulation + test
Eureka core ⼼ source code analysis
2022-2028 global industrial touch screen industry research and trend analysis report
Tlog helps Pangu framework realize microservice link log tracking