Skip to content

Commit e04c2da

Browse files
es9
1 parent 521649d commit e04c2da

File tree

322 files changed

+243
-32
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

322 files changed

+243
-32
lines changed

01-JS语言基础/数据格式处理/01-正则表达式.html

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,11 @@
9494
/^\S$/.test('𠮷'); // false \S是预定义模式,匹配所有非空白字符。只有加了u修饰符,它才能正确匹配码点大于0xFFFF的 Unicode 字符
9595
/^\S$/u.test('𠮷'); // true
9696
// y (es6) 粘连修饰符,相当于 ^$,保证每次匹配是连续的
97-
// s (es2018) 使.可以匹配任意单个字符(含行终止符)
97+
// s (es2018) 使.可以匹配任意单个字符(含行终止符) !!!
9898
/foo.bar/s.test('foo\nbar') // true
9999

100+
// es9 中 . 的全能匹配模式 us
101+
100102
/**
101103
* 【 属性 】
102104
*/
@@ -108,14 +110,14 @@
108110
// sticky 返回是否设置了y修饰符
109111
var r = /hello\d/y;
110112
r.sticky // true
111-
// dotAll
113+
// dotAll (es9) 返回是否设置了s修饰符
112114
const re = /foo.bar/s;
113-
re.dotAll // true
114-
115+
re.dotAll; // true
115116
// source (es5) 返回正则表达式的正文
116-
/abc/ig.source // "abc"
117+
118+
/abc/ig.source; // "abc"
117119
// flags (es6) 返回正则表达式的修饰符
118-
/abc/ig.flags // 'gi'
120+
/abc/ig.flags; // 'gi'
119121

120122
/**
121123
* 【4 使用一:五大内部类】
@@ -221,6 +223,31 @@
221223
* 【9 其他】
222224
* php后向引用?
223225
*/
226+
227+
/**
228+
* 【10 分组】
229+
*/
230+
// es5 匹配日期
231+
const t = '2020-03-15'.match(/(\d{4})-(\d{2})-(\d{2})/)
232+
console.log(t[1]) // 2020
233+
console.log(t[2]) // 03
234+
console.log(t[3]) // 15
235+
// es9 分组,重要
236+
const t2 = '2020-03-15'.match(/(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/)
237+
console.log(t2.groups.year) // 2020
238+
console.log(t2.groups.month) // 03
239+
console.log(t2.groups.day) // 15
240+
241+
/**
242+
* 【11 先行断言 / 后行断言】
243+
* ?= 后行断言
244+
* ?<= 先行断言(等于)
245+
* ?<! 先行断言(不等于)
246+
*/
247+
let test = 'hello world'
248+
console.log(test.match(/hello(?=\sworld)/)) // 后行断言 先找到 hello 再判断hello后面是否满足,匹配到hello
249+
console.log(test.match(/(?<=hello\s)world/)) // 先行断言 先找到 world 再判断world前面是否满足,匹配到world
250+
console.log(test.match(/(?<!helle\s)world/)) // 先行断言 先找到 world 再判断world前面是否满足,匹配到world
224251
</script>
225252
</body>
226253
</html>

01-JS语言基础/数据类型与转换/Math.html

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,16 @@
133133
// Math.acosh(x) 用于计算反双曲余弦
134134
// Math.atanh(x) 用于计算反双曲正切
135135

136-
// 【 es6 指数运算符 】
137-
// ** 指数运算符
136+
// 【 es7 指数运算符 】
137+
// ** 指数运算符
138+
// es5 中为 Math.pow(2, 5)
139+
console.log(2 ** 5)
140+
138141
1 ** 2; // 1
139142
2 ** 2 ** 3; // 256 右结合,从右至左计算
140143
let exam = 2;
141144
exam **= 2; // 4
145+
142146
</script>
143147
</body>
144148
</html>

01-JS语言基础/数据类型与转换/String.html

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,14 @@
4444
【 normalize() 】Unicode 正规化
4545
★【 includes(), startsWith(), endsWith() 】判断字符串包含 / 判断参数字符串是否在原字符串的头部 / 判断参数字符串是否在原字符串的尾部
4646
★【 repeat() 】将原字符串重复n次
47-
【 padStart(), padEnd() 】字符串补全
4847
★【 matchAll() 】返回一个正则表达式在当前字符串的所有匹配
4948
【 String.raw() 】转义字符串
5049
5150
【 es6 tag 函数 & template literals 】
5251
52+
【 es8 】
53+
* 【 padStart(), padEnd() 】字符串补全,比如统一数据前置0
54+
5355
4.【简单综合应用1】字符串占位
5456
5557
5.【简单综合应用2】统计字符串中出现次数最多的字符和次数
@@ -280,18 +282,12 @@
280282
'na'.repeat(0) // ""
281283
"Hello,".repeat(3.2) // "Hello,Hello,Hello," 如果参数是小数,向下取整
282284
"Hello,".repeat(-0.5) // "" 如果参数是 0 至 -1 之间的小数,会进行取整运算得到 -0 ,等同于 repeat 零次
283-
/**
284-
* 【 padStart(), padEnd() 】
285-
* 字符串不够指定长度,在头部或尾部补全
286-
*/
287-
'x'.padStart(4, 'ab') // 'abax'
288-
'x'.padEnd(5, 'ab') // 'xabab'
289-
'abc'.padStart(10, '0123456789') // '0123456abc'
290-
'x'.padEnd(4) // 'x '
285+
291286
/**
292287
* 【 matchAll() 】
293288
* 返回一个正则表达式在当前字符串的所有匹配
294289
*/
290+
295291
/**
296292
* 【 模板字符串 】
297293
*/
@@ -305,6 +301,16 @@
305301
* 【 String.raw() 】
306302
* 转义字符串
307303
*/
304+
305+
/**
306+
* 【 padStart(), padEnd() 】
307+
* 字符串不够指定长度,在头部或尾部补全
308+
*/
309+
'x'.padStart(4, 'ab') // 'abax'
310+
'x'.padEnd(5, 'ab') // 'xabab'
311+
'abc'.padStart(10, '0123456789') // '0123456abc'
312+
'x'.padEnd(4) // 'x '
313+
'7'.padStart(3, '0') // '007'
308314

309315

310316
//【简单综合应用1】字符串占位
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)