File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 8080// g 全局模式(global)(全文查找出现的所有pattern)
8181// i 不区分大小写(ease-insensitive)(忽略大小写)
8282// m 执行多行匹配
83- // y (es6) 相当于 ^$,保证每次匹配是连续的
8483// u (es6) Unicode模式,正确处理大于\uFFFF的Unicode字符(四个字节的 UTF-16 编码)
85- var s = '𠮷' ;
84+ var s = '𠮷' ; // \uD842\uDFB7
8685/ ^ .$ / . test ( s ) ; // false
8786/ ^ .$ / u. test ( s ) ; // true 对于码点大于0xFFFF的 Unicode 字符,点字符不能识别,必须加上u修饰符
8887/ \u{61} / . test ( 'a' ) ; // false 误认为是量词,61个u
9493/ 𠮷 { 2 } / u. test ( '𠮷𠮷' ) ; // true
9594/ ^ \S $ / . test ( '𠮷' ) ; // false \S是预定义模式,匹配所有非空白字符。只有加了u修饰符,它才能正确匹配码点大于0xFFFF的 Unicode 字符
9695/ ^ \S $ / u. test ( '𠮷' ) ; // true
97- // y (es6) 粘连修饰符
96+ // y (es6) 粘连修饰符,相当于 ^$,保证每次匹配是连续的
9897// s (es2018) 使.可以匹配任意单个字符(含行终止符)
9998/ f o o .b a r / s. test ( 'foo\nbar' ) // true
10099
Original file line number Diff line number Diff line change 4848 ★【 matchAll() 】返回一个正则表达式在当前字符串的所有匹配
4949 【 String.raw() 】转义字符串
5050
51+ 【 es6 tag 函数 & template literals 】
52+
51534.【简单综合应用1】字符串占位
5254
53555.【简单综合应用2】统计字符串中出现次数最多的字符和次数
361363 }
362364 }
363365
366+ /**
367+ * es6 tag 函数 & template literals
368+ */
369+ function Price ( strings , type ) {
370+ let s1 = strings [ 0 ] // 您此次的
371+ const retailPrice = 20
372+ const wholeSalePrice = 16
373+ let showTxt
374+ if ( type === 'retail' ) {
375+ showTxt = '购买单价是:' + retailPrice
376+ } else {
377+ showTxt = '购买的批发价是:' + wholeSalePrice
378+ }
379+ return `${ s1 } ${ showTxt } `
380+ }
381+ let showTxt = Price `您此次的${ 'retail' } `
382+ console . log ( showTxt ) // 您此次的购买单价是:20
383+
364384</ script >
365385</ body >
366386</ html >
You can’t perform that action at this time.
0 commit comments