-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
545 lines (404 loc) · 10.8 KB
/
index.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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
<!DOCTYPE html>
<html>
<head>
<title>ES6とは</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<style type="text/css">
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Ubuntu+Mono:400,700,400italic);
body {
font-family: 'Droid Serif', 'YuGothic', 'Arial', serif;
}
h1, h2, h3, h4 {
font-weight: normal;
color: #c18100;
line-height: 1.2;
}
a,
a:link,
a:visited {
color: #825700;
}
li {
margin-top: 5px;
}
li:first-child {
margin-top: 0;
}
ul ul {
margin-top: 5px;
}
.remark-code, .remark-inline-code { font-family: 'Ubuntu Mono'; }
.big {
font-size: 150px;
}
.fz60 {
font-size: 60px;
}
code.text {
white-space: normal;
}
pre {
padding: 1em;
background-color: #eee;
}
table {
width: 100%;
}
th {
padding: 0.5em;
background-color: #ffdbb6;
}
td {
padding: 0.5em;
background-color: #fff7e7;
}
tr {
background-color: #eee;
}
blockquote {
display: inline-block;
padding: 0 1em;
margin-left: 0;
background: #eee;
border-left: 5px solid #4c3300;
}
.w100 img {
width: 100%;
}
.del {
text-decoration: line-through;
}
.remark-slide-scaler {
overflow: scroll;
}
.remark-slide-number {
}
</style>
</head>
<body>
<textarea id="source">
class: center, middle
# ES6とは
2018/02/06
Kobayashi Kazuhiro (kzhrk)
---
## 本日のテーマ
- 課題チェック
- ESって?
- ESのサポートブラウザの話
- なぜES2015(ES6)なのか
- 実案件でどう使っているのか
---
class: center, middle
# 課題チェック
---
## 前回の課題
CommonChunkPluginでjquery + slickを使う
webpack.config.jsにCommonChunkPluginを設定して、slickを実行する
https://github.com/kzhrk-sandbox/training-webpack/tree/master/step4
https://kzhrk-sandbox.github.io/training-webpack/step4/public/
---
class: center, middle
# ES6とは何か
---
class: center, middle
# そもそもESとは
---
class: center, middle
# ECMAScript
---
class: center, middle
# 🤔🤔🤔
---
## ECMAとは
European Computer Manufacturers Association
欧州電子計算機工業会(現在はEcma International)
ECMAとは国際的な標準化団体の名称。HTMLでいうところのW3C。
---
## ECMAScriptとは
標準化団体のECMA Internationalが定義するJavaScriptの言語仕様。
---
## URLs
- [ECMAScriptの公式サイト](https://tc39.github.io/ecma262/)
- [GitHubリポジトリ](https://github.com/tc39/ecma262)
- [TC39のGitHubアカウント](https://github.com/tc39)
ECMA-262(規格番号) = ECMAScript
TC39 = Ecma International内でECMAScriptの策定を行っているグループ
---
## ES6の6とは
6th editionのこと。つまりversion。
6th editionから「ECMAScript 2015」仕様の名称に発行年が付加されるようになっている。
http://www.wirfs-brock.com/allen/posts/778
> why the year-based designation? The 6th edition of ECMA-262 took a long time to develop, arguably 15 years.<br>
[...]<br>
After a few years we would be talking about ES6, ES7, ES8, ES9, ES10, ES11, etc. Those numbers quickly loose any context for people who aren’t deeply involved in the standards development process.<br>
[...]<br>
We decide that TC39 would incorporate the year of release into the documents title and to encourage people to use the year when referring to a specific edition.
---
class: center, middle
# 🆖ES6 => 🆗ES2015
---
class: center, middle
# ES2015のサポートブラウザ
---
## 参考URL
- [Can I use](https://caniuse.com/#search=es6)
- [ECMAScript 6 compatibility table](http://kangax.github.io/compat-table/es6/)
- [Google Chrome Platform Status](https://www.chromestatus.com/features#ES6)
- [ECMAScript 6 support in Mozilla](https://developer.mozilla.org/en-US/docs/Web/JavaScript/New_in_JavaScript/ECMAScript_2015_support_in_Mozilla)
- [Microsoft platform status](https://developer.microsoft.com/en-us/microsoft-edge/platform/status/arrayprototypeincludeses2016/?search=es6&q=category%3Ajavascript)
- [WebKit Feature Status](https://webkit.org/status/#specification-ES6)
---
class: center, middle
# なぜES2015なのか
---
## 開発が楽になる
- コード量が減る
- よりプログラマブルにコードを書ける
- バグが減る
---
class: center, middle
# 実案件でどう使っているのか
---
## Babel.js
https://babeljs.io/
ターゲットブラウザを指定して、未対応のES2015~の記述をES5の記述に変更してくれるJavaScriptコンパイラ。
---
## Babel with webpack
.babelrc
```:js
{
"presets": ["es2015"]
}
```
webpack.config.js
```:js
[...]
module: {
rules: [
{
test: /\.js$/,
use: [{
loader: "babel-loader"
}]
}
]
},
[...]
```
---
## ES2015 features
- Arrorws
- Classes
- Enhanced Object Literals
- Template Strings
- Arguments: Default
- Arguments: Rest
- Arguments: Spread
- let, const
- Modules
- Promises
---
## Arrorws
- 関数の定義が短縮される
- thisの束縛がおきない
```:js
function sample(){
var _this = this;
_this.count = 0;
setInterval(function(){
console.log(_this.count++);
}, 1000);
}
sample();
```
```:js
function sample(){
this.count = 0;
setInterval(()=>{
console.log(this.count++);
}, 1000);
}
sample();
```
---
## Classes
```:js
class Cat {
constructor() {
this.name = 'cat';
this.voice = 'nyaa';
}
}
class MyCat extends Cat {
constructor() {
super();
this.name = 'tama';
}
}
const myCat = new MyCat();
console.log(myCat.name);
console.log(myCat.voice);
```
---
## Enhanced Object Literals
- Objectのkeyの省略
- keyの変数化
```:js
var hoge = 1;
var obj = {
hoge,
fuga() {
return 'fuga';
},
['piyo' + hoge]: 'piyo1'
};
console.log(obj);
console.log(obj.fuga());
```
---
## Template Strings
- 文字列内に変数を含めることができる
```:js
var year = 2018;
var month = 1;
var day = 6;
// es5
console.log(year + '-' + (month+1) + '-' + day);
// es2015
console.log(`${year}-${month + 1}-${day}`);
```
---
## Arguments: Default
- 関数の引数にデフォルト値の設定
```:js
function add(x, y = 1) {
console.log(x+y);
}
add(1);
```
---
## Arguments: Rest
- 関数の未定義の引数を配列として受け取る
```:js
function add(x, ...arr) {
console.log(x, arr);
}
add(1,2,3);
```
---
## Arguments: Spread
- 関数の引数として配列を受け渡す
```:js
function add(x, y, z) {
console.log(x + y + z);
}
add(...[1, 2, 3]);
add(1,...[2, 3]);
add(1, 2,...[3]);
```
---
## let, const
- let: ブロックスコープ
- const: シングルアサイン
```:js
const x = 1;
x = 2; // error
```
```:js
let x = 0;
(function() {
let x = 1;
let x = 2; // error
})();
```
---
## Modules
- モジュール定義
```:js
// math.js
export const sum = (x, y)=>{
return (x+y);
}
export const pi = '3.14';
```
```:js
// app.js
import * as math from './math';
console.log(
math.sum(1,2),
math.pi
);
```
---
## Modules
### export
```:js
export { name1, name2 };
export { variable1 as name1, variable2 as name2 };
export let name1 = 1;
export default expression;
export default function (…) { … }
export default function name1(…) { … }
export * from name1;
```
---
## Modules
### import
```:js
import defaultMember from "module-name";
import * as name from "module-name";
import { member } from "module-name";
import { member as alias } from "module-name";
import { member1, member2 } from "module-name";
import { member1, member2 as alias2 } from "module-name";
import defaultMember, { member } from "module-name";
import defaultMember, * as name from "module-name";
import "module-name";
```
---
## Promises
- 非同期処理を行う
```:js
function timeout(duration = 0, name) {
return new Promise((resolve, reject) => {
setTimeout(()=>{
console.log(`タイマー名:${name}`, `セットされた時間:${duration}`);
resolve();
}, duration);
});
}
timeout(1000, '最初').then(() => {
return timeout(2000, '2番目');
}).then(() => {
throw new Error("hmm");
}).catch(err => {
return Promise.all([timeout(2000, '3番目'), timeout(1000, '4番目')]);
});
```
---
## 他にもいろいろ
https://github.com/lukehoban/es6features
- generator
- unicode
- proxie
- map, weakmap
- symbols
- etc...
---
class: center, middle
# END
</textarea>
<script src="js/remark.min.js" type="text/javascript">
</script>
<script type="text/javascript">
var slideshow = remark.create({
navigation: {
scroll: false
}
});
</script>
</body>
</html>