File tree Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Expand file tree Collapse file tree 3 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -93,7 +93,7 @@ $ node --v8-options | grep harmony
93
93
94
94
上面命令的输出结果,会因为版本的不同而有所不同。
95
95
96
- 我写了一个[ ES-Checker] ( https://github.com/ruanyf/es-checker ) 模块,用来检查各种运行环境对ES6的支持情况。访问[ ruanyf.github.io/es-checker] ( http://ruanyf.github.io/es-checker ) ,可以看到您的默认浏览器支持ES6的程度 。运行下面的命令,可以查看本机支持ES6的程度。
96
+ 我写了一个[ ES-Checker] ( https://github.com/ruanyf/es-checker ) 模块,用来检查各种运行环境对ES6的支持情况。访问[ ruanyf.github.io/es-checker] ( http://ruanyf.github.io/es-checker ) ,可以看到您的浏览器支持ES6的程度 。运行下面的命令,可以查看本机支持ES6的程度。
97
97
98
98
``` bash
99
99
$ npm install -g es-checker
Original file line number Diff line number Diff line change 48
48
- Addy Osmani, [ Getting Literal With ES6 Template Strings] ( http://updates.html5rocks.com/2015/01/ES6-Template-Strings ) : 模板字符串的介绍
49
49
- Blake Winton, [ ES6 Templates] ( https://weblog.latte.ca/blake/tech/firefox/templates.html ) : 模板字符串的介绍
50
50
- Peter Jaszkowiak, [ How to write a template compiler in JavaScript] ( https://medium.com/@PitaJ/how-to-write-a-template-compiler-in-javascript-f174df6f32f ) : 使用模板字符串,编写一个模板编译函数
51
+ - Axel Rauschmayer, [ ES.stage3: string padding] ( http://www.2ality.com/2015/11/string-padding.html )
51
52
52
53
## 正则
53
54
Original file line number Diff line number Diff line change @@ -297,6 +297,34 @@ s.includes('Hello', 6) // false
297
297
' na' .repeat (' 3' ) // "nanana"
298
298
```
299
299
300
+ ## padStart(),padEnd()
301
+
302
+ ES7推出了字符串补全长度的功能。如果某个字符串不够指定长度,会在头部或尾部补全。` padStart ` 用于头部补全,` padEnd ` 用于尾部补全。
303
+
304
+ ``` javascript
305
+ ' x' .padStart (5 , ' ab' ) // 'ababx'
306
+ ' x' .padStart (4 , ' ab' ) // 'abax'
307
+
308
+ ' x' .padEnd (5 , ' ab' ) // 'xabab'
309
+ ' x' .padEnd (4 , ' ab' ) // 'xaba'
310
+ ```
311
+
312
+ 上面代码中,` padStart ` 和` padEnd ` 一共接受两个参数,第一个参数用来指定字符串的最小长度,第二个参数是用来补全的字符串。
313
+
314
+ 如果原字符串的长度,等于或大于指定的最小长度,则返回原字符串。
315
+
316
+ ``` javascript
317
+ ' xxx' .padStart (2 , ' ab' ) // 'xxx'
318
+ ' xxx' .padEnd (2 , ' ab' ) // 'xxx'
319
+ ```
320
+
321
+ 如果省略第二个参数,则会用空格补全长度。
322
+
323
+ ``` javascript
324
+ ' x' .padStart (4 ) // ' x'
325
+ ' x' .padEnd (4 ) // 'x '
326
+ ```
327
+
300
328
## 模板字符串
301
329
302
330
传统的JavaScript语言,输出模板通常是这样写的。
You can’t perform that action at this time.
0 commit comments