-
Notifications
You must be signed in to change notification settings - Fork 1
/
ES6_Template_String.html
212 lines (181 loc) · 6.64 KB
/
ES6_Template_String.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
<!doctype html>
<html lang="en" xmlns="http://www.w3.org/1999/html">
<head>
<meta charset="utf-8">
<title>ES6 String Template</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="stylesheet" href="css/reveal.min.css">
<link rel="stylesheet" href="css/theme/night.css" id="theme">
<link rel="stylesheet" href="lib/css/zenburn.css">
<!-- If the query includes 'print-pdf', include the PDF print sheet -->
<script>
if( window.location.search.match( /print-pdf/gi ) ) {
var link = document.createElement( 'link' );
link.rel = 'stylesheet';
link.type = 'text/css';
link.href = 'css/print/pdf.css';
document.getElementsByTagName( 'head' )[0].appendChild( link );
}
</script>
<!--[if lt IE 9]>
<script src="lib/js/html5shiv.js"></script>
<![endif]-->
<style>
.authorArea {
margin-top: 100px !important;
text-align: right;
font-size: 90% !important;
}
.code {
}
section {
text-align: left;
}
pre {
margin: 0px !important;
font-size: 105% !important;
}
code {
font-family: cursive !important;
}
small {
font-size: .8em !important;
margin: 10px 0px !important;
}
ul {
margin: 10px 0px !important;
list-style: none !important;
}
</style>
</head>
<body>
<div class="reveal">
<div class="slides">
<section>
<h2>ES6 String Template</h2>
<div class="authorArea">
<p>By Hao Ju Zheng</p>
<p>github: <a href="https://github.com/hjzheng">https://github.com/hjzheng</a></p>
</div>
</section>
<section>
<h2>什么是ES6 <a href="http://tc39wiki.calculist.org/es6/template-strings/">String Template</a></h2>
<p>
一种允许在字符串中嵌入的表达式的技术, 也被称为字符串插值, 该技术作为ES6规范,
很多浏览器都不支持, 据我了解的情况,FireFox34及以上版本支持, <a href="https://twitter.com/addyosmani/status/541978036904554496?utm_source=javascriptweekly&utm_medium=email">Chrome也会马上支持</a>。
</p>
</section>
<section>
<h2>使用ES6 String Template (1)</h2>
<small>Basic usage with an expression placeholder</small>
<pre><code data-trim contenteditable>
//Basic usage with an expression placeholder
var person = 'Hao Ju Zheng';
console.log(`Yo! My name is ${person}`);
</code></pre>
</section>
<section>
<h2>使用ES6 String Template (2)</h2>
<small>Expressions work just as well with object literals</small>
<pre><code data-trim contenteditable>
//Expressions work just as well with object literals
var user = {name: 'Zhen Ou Yun'};
console.log(`Thanks, ${user.name}`);
console.log(`The price is ${10*6} RMB`);
</code></pre>
</section>
<section>
<h2>使用ES6 String Template (3)</h2>
<small>Expression interpolation, One use is readable inline math</small>
<pre><code data-trim contenteditable>
//Expression interpolation, One use is readable inline math.
var a = 50;
var b = 100;
console.log(`The number is ${a + b} and not ${ 2 * a +b }`);
</code></pre>
</section>
<section>
<h2>使用ES6 String Template (4)</h2>
<small>Multi-line strings without needing \n\</small>
<pre><code data-trim contenteditable>
//Multi-line strings without needing \n\
console.log(`string text line 1
string text line 2`);
</code></pre>
</section>
<section>
<h2>使用ES6 String Template (5)</h2>
<small>Function inside expressions</small>
<pre><code data-trim contenteditable>
//Function inside expressions
function fn() {return "result"}
console.log(`foo ${fn()} bar`);
</code></pre>
</section>
<section>
<h2>ES6 String Template用途</h2>
<ul>
<li>国际化</li>
<li>自定义html模板</li>
<li>多行字符串</li>
</ul>
</section>
<section>
<h3>ES6 String Template 如何兼容其他浏览器?</h3>
</section>
<section>
<h2>使用multiline和EJS</h2>
<ul>
<li><a href="https://github.com/sindresorhus/multiline">multiline</a></li>
<li><a href="https://github.com/tj/ejs">EJS</a></li>
</ul>
</section>
<section>
<h2><a href="https://github.com/hjzheng/es6TemplateString">es6TemplateString</a></h2>
</section>
<section data-markdown>
<script type="text/template">
## 扩展阅读
- [EJS][0]
- [multiline][1]
- [es6TemplateString][3]
- [ES6 Features][2]
- [ECMAScript 6入门][4]
[0]:https://github.com/tj/ejs
[1]:https://github.com/sindresorhus/multiline
[2]:https://github.com/lukehoban/es6features#template-strings
[3]:https://github.com/hjzheng/es6TemplateString
[4]:http://es6.ruanyifeng.com/
</script>
</section>
<section>
<section>
<h2>谢谢观赏</h2>
<div class="authorArea">
<p>2014-12-15</p>
<p>如果你喜欢,请<a href="https://github.com/hjzheng/CUF_PPTs">star</a>我</p>
</div>
</section>
</section>
</div>
</div>
<script src="lib/js/head.min.js"></script>
<script src="js/reveal.min.js"></script>
<script>
Reveal.initialize({
history: true,
transition: 'linear',
progress: true,
math: {
// mathjax: 'http://cdn.mathjax.org/mathjax/latest/MathJax.js',
config: 'TeX-AMS_HTML-full'
},
dependencies: [
{ src: 'lib/js/classList.js', condition: function() { return !document.body.classList; } },
{ src: 'plugin/markdown/marked.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } },
{ src: 'plugin/markdown/markdown.js', condition: function() { return !!document.querySelector( '[data-markdown]' ); } }
]
});
</script>
</body>
</html>