mirror of
https://github.com/ruanyf/es6tutorial.git
synced 2024-04-21 12:32:22 +00:00
edit module, array
This commit is contained in:
+11
-4
@@ -286,14 +286,14 @@ function authorize(user, action) {
|
||||
var x = 1;
|
||||
var y = 2;
|
||||
|
||||
console.log(`${x} + ${y} = ${x+y}`)
|
||||
`${x} + ${y} = ${x + y}`
|
||||
// "1 + 2 = 3"
|
||||
|
||||
console.log(`${x} + ${y*2} = ${x+y*2}`)
|
||||
`${x} + ${y * 2} = ${x + y * 2}`
|
||||
// "1 + 4 = 5"
|
||||
|
||||
var obj = {x: 1, y: 2};
|
||||
console.log(`${obj.x + obj.y}`)
|
||||
`${obj.x + obj.y}`
|
||||
// 3
|
||||
```
|
||||
|
||||
@@ -304,7 +304,7 @@ function fn() {
|
||||
return "Hello World";
|
||||
}
|
||||
|
||||
console.log(`foo ${fn()} bar`);
|
||||
`foo ${fn()} bar`
|
||||
// foo Hello World bar
|
||||
```
|
||||
|
||||
@@ -318,6 +318,13 @@ var msg = `Hello, ${place}`;
|
||||
// 报错
|
||||
```
|
||||
|
||||
由于模板字符串的大括号内部,就是执行JavaScript代码,因此如果表达式放在引号之中,将会原样输出。
|
||||
|
||||
```javascript
|
||||
`Hello ${'World'}`
|
||||
// "Hello World"
|
||||
```
|
||||
|
||||
## 标签模板
|
||||
|
||||
模板字符串的功能,不仅仅是上面这些。它可以紧跟在一个函数名后面,该函数将被调用来处理这个模板字符串。这被称为“标签模板”功能(tagged template)。
|
||||
|
||||
Reference in New Issue
Block a user