æ¬æ¥ãJavaScriptããã¥ã¢ã«ã®ç¿»èš³ã®ç¬¬8éšã§ã¯ãES6æšæºã®ãªãªãŒã¹åŸã«ç»å Žããèšèªã®æ©èœã確èªããŸãã äœããã®æ¹æ³ã§ããããã®å¯èœæ§ã®å€ãã«ä»¥åã«åºããããŸãããã©ããã§ãã詳现ã«èª¬æããã©ããã§åœããåã®ããšãèããŠããŸãã ã¬ã€ãã®ãã®ã»ã¯ã·ã§ã³ã¯ããããŸã§è§Šããããšã®ãªãããã€ãã®ãããã¯ã®é瀺ãšãšãã«ãææ°ã®JavaScriptã®åéã®åå¿è
éçºè
ã®ç¥èãåçåããããšãç®çãšããŠããŸãã
â
ããŒã1ïŒæåã®ããã°ã©ã ãèšèªæ©èœãæšæºâ
ããŒã2ïŒã³ãŒãã¹ã¿ã€ã«ãšããã°ã©ã æ§é â
ããŒã3ïŒå€æ°ãããŒã¿åãåŒããªããžã§ã¯ãâ
ããŒã4ïŒæ©èœâ
ããŒã5ïŒé
åãšã«ãŒãâ
ããŒã6ïŒäŸå€ãã»ãã³ãã³ãã¯ã€ã«ãã«ãŒããªãã©ã«â
ããŒã7ïŒå³æ Œã¢ãŒãããã®ããŒã¯ãŒããã€ãã³ããã¢ãžã¥ãŒã«ãæ°åŠèšç®â
ããŒã8ïŒES6æ©èœã®æŠèŠâ
ããŒã9ïŒES7ãES8ãããã³ES9æšæºã®æŠèŠES6ã«ã€ããŠ
ES6ãŸãã¯ESMAScript 2015ïŒãããã¯å
¬åŒåã§ããã誰ããES6ãšåŒãã§ããŸããïŒãšåŒã¶æ¹ãæ£ããES6æšæºã¯ã以åã®æšæºã§ããES5.1ã®ãªãªãŒã¹ãã4幎åŸã«ç»å ŽããŸããã ES5.1æšæºã«æºæ ãããã¹ãŠã®ãã®ãéçºããã®ã«çŽ10幎ããããŸããã æè¿ã§ã¯ããã®æšæºã«ç»å Žãããã¹ãŠã®ãã®ãJSéçºè
ã®éåžžã®ããŒã«ã«ãªã£ãŠããŸãã ES6ã¯èšèªã倧å¹
ã«å€æŽããããšã«æ³šæããŠãã ããïŒä»¥åã®ããŒãžã§ã³ãšã®åŸæ¹äºææ§ãç¶æããŸãïŒã ãããã®å€æŽã®å€§ãããç解ããããã«ãES5æšæºã説æããããã¥ã¡ã³ãã®ãµã€ãºã¯çŽ250ããŒãžã§ãããæšæºES6ã¯ãã§ã«çŽ600ããŒãžã®ããã¥ã¡ã³ãã«èšèŒãããŠããããšã«æ³šæããŠãã ããã
ES2015æšæºã®æãéèŠãªé©æ°ã®ãªã¹ãã«ã¯ã次ã®ãã®ãå«ãŸããŸãã
- ç¢å°é¢æ°
- çŽæ
- çºé»æ©
- ããŒã¯ãŒã
let
ããã³const
- ã¯ã©ã¹
- ã¢ãžã¥ãŒã«
- ãã³ãã¬ãŒããªãã©ã«ãµããŒã
- ããã©ã«ãã®é¢æ°ãã©ã¡ãŒã¿ãŒã®ãµããŒã
- ã¹ãã¬ããæŒç®å
- ç Žå£çãªå²ãåœãŠ
- ãªããžã§ã¯ããªãã©ã«ã®æ¡åŒµ
- ã«ãŒãã®
for...of
Map
ããã³Set
ããŒã¿æ§é ã®ãµããŒã
ãããã®å¯èœæ§ãèæ
®ããŠãã ããã
ç¢å°é¢æ°
ç¢å°é¢æ°ã¯ãJavaScriptã³ãŒãã®ã«ãã¯ã¢ã³ããã£ãŒã«ãå€æŽããŸããã å€èŠ³ã®ç¹ã§ã¯ããããã䜿çšãããšãé¢æ°å®£èšãããçãç°¡åã«ãªããŸãã ãããéåžžã®é¢æ°ã®å®£èšã§ãã
const foo = function foo() {
ããããã»ãŒåãïŒäžèšã«å®å
šã«é¡äŒŒããŠããããã§ã¯ãããŸãããïŒç¢å°é¢æ°ã
const foo = () => {
ç¢å°é¢æ°ã®æ¬äœã1è¡ã®ã¿ã§æ§æããããã®çµæããã®é¢æ°ããè¿ãããå¿
èŠãããå Žåã¯ãããã«çãæžã蟌ãŸããŸãã
const foo = () => doSomething()
ç¢å°é¢æ°ããã©ã¡ãŒã¿ã1ã€ããåãåããªãå Žåã次ã®ããã«èšè¿°ã§ããŸãã
const foo = param => doSomething(param)
ç¢å°é¢æ°ã®åºçŸã«ãããéåžžã®é¢æ°ã¯æ¶ãããã³ãŒãå
ã§äœ¿çšããããšãã§ãã以åãšåãããã«æ©èœããããšã«æ³šæããŠãã ããã
ãã®ããŒã¯ãŒãã®æ©èœã¯ç¢å°æ©èœã«ãããŸã
ç¢å°é¢æ°ã¯
this
åºæå€ãæãããå®è¡ã³ã³ããã¹ãããç¶æ¿ããŸãã
ããã«ãããéåžžã®é¢æ°ã䜿çšããå Žåãã³ã³ããã¹ããä¿æããããã«
var that = this
ãããªæ§é ã䜿çšããå¿
èŠããã£ãåé¡ããªããªããŸãã ãã ããããã¥ã¢ã«ã®åã®éšåã§ç€ºããããã«ããã®å€æŽã¯ç¢å°é¢æ°ã䜿çšããæ©èœãšãã®é©çšç¯å²ã«æ·±å»ãªåœ±é¿ãäžããŸãã
çŽæ
Promiseã䜿çšãããšããã³ãŒã«ããã¯å°çããšåŒã°ããããç¥ãããåé¡ãåãé€ãããšãã§ããŸããããã®äœ¿çšã¯ããªãè€éãªæ§é ã®äœ¿çšãæå³ããŸãã ãã®åé¡ã¯ãçŽæã«åºã¥ã
async/await
ã³ã³ã¹ãã©ã¯ãã®åºçŸã«ãããES2017æšæºã§è§£æ±ºãããŸããã
JavaScriptéçºè
ã¯ãES2015æšæºã®åã«ãããã¹ã䜿çšããããã«ããŸããŸãªã©ã€ãã©ãªã䜿çšããŸããïŒããšãã°ãjQueryãqãdeferred.jsãvowïŒã ããã¯ããã®ã¡ã«ããºã ã®éèŠæ§ãšé¢é£æ§ã瀺ããŠããŸãã ããŸããŸãªã©ã€ãã©ãªãããŸããŸãªæ¹æ³ã§å®è£
ããŠããããããã®åéã§ã®æšæºã®åºçŸã¯éåžžã«è¯å®çãªäºå®ãšèããããšãã§ããŸãã
以äžã¯ãã³ãŒã«ããã¯é¢æ°ïŒã³ãŒã«ããã¯ïŒã䜿çšããŠèšè¿°ãããã³ãŒãã§ãã
setTimeout(function() { console.log('I promised to run after 1s') setTimeout(function() { console.log('I promised to run after 2s') }, 1000) }, 1000)
promiseã䜿çšããŠãããã次ã®ããã«æžãæããããšãã§ããŸãã
const wait = () => new Promise((resolve, reject) => { setTimeout(resolve, 1000) }) wait().then(() => { console.log('I promised to run after 1s') return wait() }) .then(() => console.log('I promised to run after 2s'))
çºé»æ©
ãžã§ãã¬ãŒã¿ãŒã¯ãç¬èªã®å®è¡ãäžæåæ¢ããŠåéã§ããç¹å¥ãªæ©èœã§ãã ããã«ããããžã§ãã¬ãŒã¿ãŒãã¢ã€ãã«ç¶æ
ã®ãšãã«å¥ã®ã³ãŒããå®è¡ã§ããŸãã
ãžã§ãã¬ãŒã¿ãŒã¯ãèªåã®é çªã§å®è¡ããåŸ
æ©ãããŠããå¥ã®ã³ãŒããäžæåæ¢ããŠèš±å¯ããå¿
èŠããããšå€æããŸãã åæã«ããžã§ãã¬ãŒã¿ãŒã¯ããã®æäœïŒçµæãåŸ
æ©ããŠããïŒãå®äºããåŸãå®è¡ãç¶ç¶ããæ©äŒããããŸãã
ããã¯ãã¹ãŠãåäžã®åçŽãªããŒã¯ãŒã
yield
ãããã§è¡ãããŸãã ãã®ããŒã¯ãŒãããžã§ãã¬ãŒã¿ãŒã§èŠã€ãããšããã®å®è¡ã¯äžæåæ¢ãããŸãã
ãžã§ãã¬ãŒã¿ã«ã¯ããã®ããŒã¯ãŒãã䜿çšããŠå€æ°ã®è¡ãå«ããããšãã§ãããã®å®è¡ãæ°åäžæåæ¢ããŸãã ãžã§ãã¬ãŒã¿ãŒã¯ã
*function
æ§é ã䜿çšããŠå®£èšãããŸãã åèª
function
åã®ãã®ã¢ã¹ã¿ãªã¹ã¯ã¯ãCãC ++ãGoãªã©ã®èšèªã§äœ¿çšããããã€ã³ã¿ãŒéåç
§æŒç®åã®ãããªãã®ã«ã¯äœ¿çšããªãã§ãã ããã
ãžã§ãã¬ãŒã¿ãŒã¯ãæ°ããJavaScriptããã°ã©ãã³ã°ãã©ãã€ã ã®åºçŸã瀺ããŸãã ç¹ã«ããžã§ãã¬ãŒã¿ãŒãšä»ã®ã³ãŒãéã®åæ¹åã®ããŒã¿äº€æãå¯èœã«ããããã°ã©ã ãããã³ã°ããããªãé·å¯¿åœã®
while
ã«ãŒããäœæã§ããŸãã
ãžã§ãã¬ãŒã¿ãŒã®åäœã®ç¹åŸŽã瀺ãäŸãèããŠã¿ãŸãããã ããããžã§ãã¬ãŒã¿ãŒã§ãã
function *calculator(input) { var doubleThat = 2 * (yield (input / 2)) var another = yield (doubleThat) return (input * doubleThat * another) }
ãã®ã³ãã³ãã䜿çšããŠãåæåããŸãã
const calc = calculator(10)
次ã«ãã€ãã¬ãŒã¿ã«æ»ããŸãã
calc.next()
ãã®ã³ãã³ãã¯ã€ãã¬ãŒã¿ãèµ·åãããã®ãããªãªããžã§ã¯ããè¿ããŸãã
{ done: false value: 5 }
ããã§æ¬¡ã®ããšãèµ·ãããŸãã ã³ãŒãã¯ããžã§ãã¬ãŒã¿ãŒã³ã³ã¹ãã©ã¯ã¿ãŒã«æž¡ããã
input
å€ã䜿çšããŠé¢æ°ãå®è¡ããŸãã çæã³ãŒãã¯ã
yield
ããŒã¯ãŒããèŠã€ãããŸã§å®è¡ãããŸãã ãã®æç¹ã§ã
input
ã
2
ã§é€ç®ããçµæãè¿ããŸãã
input
ã¯
10
ã§ãããããæ°å€
5
ãåŸãããŸãã ã€ãã¬ãŒã¿ã®ãããã§ãã®çªå·ãåŸãããŸãããŸããã€ãã¬ãŒã¿ã«ãã£ãŠããžã§ãã¬ãŒã¿ããŸã å®äºããŠããªãïŒã€ãã¬ãŒã¿ããè¿ããããªããžã§ã¯ãã®
done
ããããã£ã
false
èšå®ãããŠ
false
ïŒããšãã€ãŸãé¢æ°ãäžæåæ¢ããŠããããšã瀺ããŸãã
å埩åã次ã«åŒã³åºããããšãã«ãæ°å€
7
ããžã§ãã¬ãŒã¿ãŒã«æž¡ããŸãã
calc.next(7)
ããã«å¿ããŠãå埩åã¯æ¬¡ã®ãªããžã§ã¯ããè¿ããŸãã
{ done: false value: 14 }
ããã§ã¯ãæ°å€
7
ã䜿çšããŠ
doubleThat
å€ãèšç®ã
doubleThat
ã
äžèŠã
input / 2
ã³ãŒãã¯äœããã®é¢æ°ãžã®åŒæ°ã®ãããªãã®ã«èŠãããããããŸããããããã¯æåã®å埩ã§è¿ãããå€ã«ãããŸããã ããã§ã¯ããã®å€ãã¹ãããããŠãæ°ããå
¥åå€
7
ã䜿çšããããã«
2
æããŸãã ãã®åŸã2çªç®ã®
yield
ããŒã¯ãŒãã«å°éããŸãããã®çµæã2çªç®ã®å埩ã§ååŸãããå€ã¯
14
ã§ãã
æåŸã®æ¬¡ã®å埩ã§ãæ°å€
100
ããžã§ãã¬ãŒã¿ãŒã«æž¡ããŸãã
calc.next(100)
å¿çãšããŠã次ã®ãªããžã§ã¯ããååŸããŸãã
{ done: true value: 14000 }
å埩ãå®äºãïŒ
yield
ããŒã¯ãŒãããžã§ãã¬ãŒã¿ã§èŠã€ãããªããªã£ãïŒãåŒã®è©äŸ¡çµæ
(input * doubleThat * another)
ãªããžã§ã¯ããã€ãŸã
10 * 14 * 100
ãšã€ãã¬ãŒã¿ã®å®äºã®è¡šç€ºïŒ
done: true
ïŒã§è¿ãããŸãã
ããŒã¯ãŒãletããã³const
JavaScriptã¯åžžã«å€æ°ã宣èšããããã«
var
ããŒã¯ãŒãã䜿çšããŠããŸãã ãã®ãããªå€æ°ã«ã¯æ©èœçãªç¯å²ããããŸãã
let
ããŒã¯ãŒããš
const
ããŒã¯ãŒãããããã䜿çšãããšããããã¯ã¹ã³ãŒããæã€å€æ°ãšå®æ°ã宣èšã§ããŸãã
ããã¯ãããšãã°ãã«ãŒãå
ã
if
ãããã¯å
ããŸãã¯äžæ¬åŒ§ã§å¶éãããéåžžã®ã³ãŒããããã¯å
ã§
let
ããŒã¯ãŒãã䜿çšããŠå®£èšãããå€æ°ã¯ããã®ãããã¯ãè¶
ããªãããšãæå³ããŸãã
var
宣èšãããå€æ°ã¯ãã®ãããªãããã¯ã«ä¿æãããã宣èšãããã¬ãã«ã®é¢æ°ã§äœ¿çšå¯èœã«ãªããŸãã
const
ããŒã¯ãŒãã¯
let
ãšåãããã«æ©èœ
let
ãããã䜿çšãããšãäžå€ã®å®æ°ã宣èšãããŸãã
ææ°ã®JSã³ãŒãã§ã¯ã
var
ããŒã¯ãŒãã¯ã»ãšãã©äœ¿çšãããŸããã
let
ããŒã¯ãŒããš
const
ããŒã¯ãŒãã«
const
代ãããŸããã åæã«ãããã¯ç°åžžã«æãããããããŸãããã
const
ããŒã¯ãŒãã¯ä»æ¥éåžžã«åºã䜿çšãããŠãããããã¯çŸä»£ã®ããã°ã©ãã³ã°ã«ããããšã³ãã£ãã£ã®å
責ã®ã¢ã€ãã¢ã®äººæ°ã瀺ããŠããŸãã
ã¯ã©ã¹
JavaScriptããããã¿ã€ãç¶æ¿ã¢ãã«ã䜿çšããå¯äžã®éåžžã«æ®åããèšèªã§ããããšãå€æããŸããã ãã®ãããªç°å¢ã§ã¯ãã¯ã©ã¹ããŒã¹ã®ç¶æ¿ã¡ã«ããºã ãå®è£
ããèšèªããJSã«åãæ¿ããããã°ã©ããŒã¯äžå¿«ã«æããŸããã ES2015æšæºã§ã¯ãJavaScriptã§ã¯ã©ã¹ã®ãµããŒããå°å
¥ãããŸããã ããã¯æ¬è³ªçã«ããããã¿ã€ãã䜿çšããJSå
éšã¡ã«ããºã ãåãå·»ããæ§æç³ãã§ãã ãã ããããã¯JSã¢ããªã±ãŒã·ã§ã³ãæ£ç¢ºã«æžã蟌ãæ¹æ³ã«åœ±é¿ããŸãã
JavaScriptã®ç¶æ¿ã¡ã«ããºã ã¯ãä»ã®ãªããžã§ã¯ãæåèšèªã®åæ§ã®ã¡ã«ããºã ã®ããã«ãªããŸããã
class Person { constructor(name) { this.name = name } hello() { return 'Hello, I am ' + this.name + '.' } } class Actor extends Person { hello() { return super.hello() + ' I am an actor.' } } var tomCruise = new Actor('Tom Cruise') console.log(tomCruise.hello())
ãã®ããã°ã©ã ã¯ãã
Hello, I am Tom Cruise. I am an actor
ã³ã³ãœãŒã«ãžã®
Hello, I am Tom Cruise. I am an actor
ãšããããã¹ãã衚瀺ããŸã
Hello, I am Tom Cruise. I am an actor
Hello, I am Tom Cruise. I am an actor
ã§ãã
JSã¯ã©ã¹ã§ã¯ãã€ã³ã¹ã¿ã³ã¹å€æ°ã¯å®£èšã§ããŸãã;ã³ã³ã¹ãã©ã¯ã¿ãŒã§åæåããå¿
èŠããããŸãã
ã¯ã©ã¹ã³ã³ã¹ãã©ã¯ã¿ãŒ
ã¯ã©ã¹ã«ã¯ç¹å¥ãªã¡ãœãã
constructor
ããããŸããããã¯ã
new
ããŒã¯ãŒãã䜿çšããŠã¯ã©ã¹ã®ã€ã³ã¹ã¿ã³ã¹ãäœæããããšãã«åŒã³åºãããŸãã
âããŒã¯ãŒãã¹ãŒããŒ
super
ããŒã¯ãŒãã䜿çšãããšãåå«ã¯ã©ã¹ãã芪ã¯ã©ã¹ã«ã¢ã¯ã»ã¹ã§ããŸãã
âã²ãã¿ãŒãšã»ãã¿ãŒ
ããããã£ã®ã²ãã¿ãŒã¯æ¬¡ã®ããã«èšå®ã§ããŸãã
class Person { get fullName() { return `${this.firstName} ${this.lastName}` } }
ã»ãã¿ãŒã¯æ¬¡ã®ããã«èšè¿°ã§ããŸãã
class Person { set age(years) { this.theAge = years } }
ãããã¯ãé¢æ°ã§ã¯ãªããªããžã§ã¯ãã®éåžžã®ããããã£ã§ãããã®ããã«ãgetterããã³setterã§åäœããŸãã
ã¢ãžã¥ãŒã«
ES2015æšæºã®åã«ã¯ãã¢ãžã¥ãŒã«ãæäœããããã®ç«¶åããã¢ãããŒããããã€ããããŸããã ç¹ã«ãRequireJSããã³CommonJSãã¯ãããžãŒã«ã€ããŠè©±ããŸãã ãã®ç¶æ³ã«ãããJSéçºè
ã®ã³ââãã¥ããã£ã§ã¯æèŠã®çžéãçããŸããã
çŸåšãES2015ã®ã¢ãžã¥ãŒã«ã®æšæºåã®ãããã§ãç¶æ³ã¯åŸã
ã«æ£åžžåããŠããŸãã
modulesã¢ãžã¥ãŒã«ã®ã€ã³ããŒã
ã¢ãžã¥ãŒã«ã¯ã
import...from...
圢åŒã®æ§æã䜿çšããŠ
import...from...
以äžã«äŸã瀺ããŸãã
import * as something from 'mymodule' import React from 'react' import { React, Component } from 'react' import React as MyLibrary from 'react'
modulesã¢ãžã¥ãŒã«ã®ãšã¯ã¹ããŒã
ã¢ãžã¥ãŒã«ã®å
éšã¡ã«ããºã ã¯å€éšããã¯éããããŠããŸãããã¢ãžã¥ãŒã«ããã¯ãä»ã®ã¢ãžã¥ãŒã«ãæäŸã§ãããã¹ãŠã®ãã®ããšã¯ã¹ããŒãã§ããŸãã ããã¯ã
export
ããŒã¯ãŒãã䜿çšããŠè¡ãããŸãã
export var foo = 2 export function bar() { }
âãã³ãã¬ãŒããªãã©ã«
ãã³ãã¬ãŒããªãã©ã«ã¯ãJavaScriptã§æååãèšè¿°ããæ°ããæ¹æ³ã§ãã å€èŠ³ã¯æ¬¡ã®ãšããã§ãã
const aString = `A string`
ããã«ããã³ãã¬ãŒããªãã©ã«ã®æ§æã䜿çšãããšãæååã«åŒãåã蟌ã¿ãè£éããããšãã§ããŸãã ããã¯ããã©ãŒã
${a_variable}
æ§ç¯ã䜿çšããŠè¡ãããŸãã 以äžã¯ããã®äœ¿çšã®ç°¡åãªäŸã§ãã
const v = 'test' const str = `something ${v}`
åŒãè©äŸ¡ãããã®çµæãæååã«ä»£å
¥ããæ©èœã瀺ããããè€éãªäŸã§ãã
const str = `something ${1 + 2 + 3}` const str2 = `something ${foo() ? 'x' : 'y' }`
ãã³ãã¬ãŒããªãã©ã«ã䜿çšãããããã§ãè€æ°è¡ã®æååã宣èšããã®ãã¯ããã«ç°¡åã«ãªããŸããã
const str3 = `Hey this string is awesome!`
ES2015ããåã®èšèªã§äœ¿çšå¯èœãªæ©èœã䜿çšããéã«ããããè€æ°è¡ã®æååãèšè¿°ããããã«å¿
èŠã ã£ããã®ãšæ¯èŒããŠãã ããã
var str = 'One\n' + 'Two\n' + 'Three'
ããã©ã«ãã®é¢æ°ãã©ã¡ãŒã¿ãŒ
çŸåšãé¢æ°ã¯ããã©ã«ãã§äœ¿çšããããã©ã¡ãŒã¿ããµããŒãããŠããŸã-é¢æ°ãåŒã³åºããšãã«å¯Ÿå¿ããåŒæ°ãæž¡ãããªãå Žåã
const foo = function(index = 0, testing = true) { } foo()
ã¹ãã¬ããæŒç®å
ã¹ãã¬ããæŒç®åïŒæ¡åŒµæŒç®åïŒã䜿çšãããšãé
åããªããžã§ã¯ãããŸãã¯æååããæ¡åŒµãã§ããŸãã ãã®æŒç®åã¯ã3ã€ã®ãããïŒ
...
ïŒã®ããã«èŠã
...
ã ãŸããé
åã®äŸãèããŠã¿ãŸãããã
const a = [1, 2, 3]
ãã®é
åã«åºã¥ããŠæ°ããé
åãäœæããæ¹æ³ã¯æ¬¡ã®ãšããã§ãã
const b = [...a, 4, 5, 6]
é
åã®ã³ããŒãäœæããæ¹æ³ã¯æ¬¡ã®ãšããã§ãã
const c = [...a]
ãã®æŒç®åã¯ãªããžã§ã¯ãã§ãæ©èœããŸãã ããšãã°ãããã䜿çšããŠãªããžã§ã¯ããè€è£œããæ¹æ³ã次ã«ç€ºããŸãã
const newObj = { ...oldObj }
æååã«ã¹ãã¬ããæŒç®åãé©çšãããšãé
åã«å€æã§ããŸããé
åã®åèŠçŽ ã«ã¯ããã®æååã®1æåãå«ãŸããŸãã
const hey = 'hey' const arrayized = [...hey]
ãã®æŒç®åã¯ãã¢ããªã±ãŒã·ã§ã³ã®äžèšã®ããªã¢ã³ãã«å ããŠãéåžžã®åŒæ°ã®ãªã¹ããæåŸ
ããé¢æ°ãåŒã³åºãããããã®åŒæ°ãæã€é
åãæž¡ããšãã«äœ¿çšãããšäŸ¿å©ã§ãã
const f = (foo, bar) => {} const a = [1, 2] f(...a)
以åã¯ãããã¯
f.apply(null, a)
ãšãã圢åŒã®æ§é ã䜿çšããŠè¡ãããŠããŸãããããã®ãããªã³ãŒãã¯æžãã®ãé£ãããèªã¿ã«ããã§ãã
ç Žå£çãªå²ãåœãŠ
æ§é åå²ãåœãŠææ³ã䜿çšãããšãããšãã°ããªããžã§ã¯ããååŸãããã®ãªããžã§ã¯ãããå€ãæœåºããŠãååä»ãå€æ°ãŸãã¯å®æ°ã«å
¥ããããšãã§ããŸãã
const person = { firstName: 'Tom', lastName: 'Cruise', actor: true, age: 54, } const {firstName: name, age} = person
ããã§ã¯ã
firstName
ããããã£ãš
age
ããããã£ããªããžã§ã¯ãããååŸãããŸãã
age
ããããã£ã¯ãåãååã§å®£èšãããå®æ°ã«æžã蟌ãŸãã
firstName
ããããã£ã¯ãæœåºåŸã«å®æ°
name
åé¡ãããŸãã
ç Žå£çãªå²ãåœãŠã¯ãé
åã®æäœã«ãé©ããŠããŸãã
const a = [1,2,3,4,5] const [first, second, , , fifth] = a
first
ã
second
ããã³
fifth
å®æ°ã¯ãããããé
åã®æåã2çªç®ãããã³5çªç®ã®èŠçŽ ãååŸããŸãã
ãªããžã§ã¯ããªãã©ã«ã®æ¡åŒµ
ES2015ã¯ããªããžã§ã¯ããªãã©ã«ã䜿çšããŠãªããžã§ã¯ããèšè¿°ããæ©èœã倧å¹
ã«æ¡åŒµããŸããã
variablesãªããžã§ã¯ããžã®å€æ°ã®å
å«ã®ç°¡çŽ å
以åã¯ãå€æ°ããªããžã§ã¯ãã®ããããã£ã«å²ãåœãŠãããã«ã次ã®æ§æã䜿çšããå¿
èŠããããŸããã
const something = 'y' const x = { something: something }
ããã§åãããšãã§ããããã«ãªããŸããã
const something = 'y' const x = { something }
âãããã¿ã€ã
ãªããžã§ã¯ãã®ãããã¿ã€ãã¯ã次ã®æ§æã䜿çšããŠèšå®ã§ããããã«ãªããŸããã
const anObject = { y: 'y' } const x = { __proto__: anObject }
âããŒã¯ãŒãsuper
super
ããŒã¯ãŒãã䜿çšãããšããªããžã§ã¯ãã¯ãããã¿ã€ããªããžã§ã¯ãã«ã¢ã¯ã»ã¹ã§ããŸãã ããšãã°ããããã®ãªããžã§ã¯ãèªäœã®ã¡ãœãããšåãååãæã€ã¡ãœãããåŒã³åºããŸãã
const anObject = { y: 'y', test: () => 'zoo' } const x = { __proto__: anObject, test() { return super.test() + 'x' } } x.test()
âèšç®ãããããããã£å
èšç®ãããããããã£åã¯ããªããžã§ã¯ãäœæã®æ®µéã§åœ¢æãããŸãã
const x = { ['a' + '_' + 'b']: 'z' } x.a_b
ã«ãŒãã®for ...
2009幎ãES5æšæºã§ã¯ã
forEach()
ã«ãŒããç»å ŽããŸããã ããã¯äŸ¿å©ãªæ§é ã§ããããã®æ¬ ç¹ã¯ããã®ãããªãµã€ã¯ã«ãäžæããã®ãéåžžã«äžäŸ¿ã§ãããšããäºå®ã§ãã ã«ãŒãã®å®è¡ãæ£åžžã«å®äºããåã«äžæããå¿
èŠãããç¶æ³ã§ã®å€å
žçãª
for
ã«ãŒãã¯ãã¯ããã«é©åãªéžæã§ãã
for...of
ã«ãŒããES2015ã«ç»å ŽããŸãããããã¯ãäžæ¹ã§ãã®ç°¡æœãªæ§æãšäŸ¿å©ãª
forEach
ã«ãã£ãŠåºå¥ãããä»æ¹ã§ãã«ãŒãããã®æ©æçµäºã®å¯èœæ§ããµããŒãããŸãã
以äžã«
for...of
ã«ãŒãã®äŸãããã€ã瀺ããŸãã
ããŒã¿æ§é ã®ãããã³ã°ãšèšå®
ES2015ã¯ã
Map
ããã³
Set
ããŒã¿æ§é ãå°å
¥ããŸããïŒãŸãããããã®ã匱ããããŒãžã§ã³
WeakMap
ããã³
WeakSet
ã䜿çšãããšããã¬ããŒãžã³ã¬ã¯ã¿ãŒã-JSãšã³ãžã³ã®ã¡ã¢ãªç®¡çãæ
åœããã¡ã«ããºã ãã®ããã©ãŒãã³ã¹ãåäžããŸãïŒã ãããã¯éåžžã«äžè¬çãªããŒã¿æ§é ã§ãããå
¬åŒã®å®è£
ãç»å Žããåã«ãå©çšå¯èœãªèšèªããŒã«ã䜿çšããŠæš¡å£ããå¿
èŠããããŸããã
ãŸãšã
æ¬æ¥ãES2015æšæºã®æ©èœã確èªããŸãããããã¯ãèšèªã®çŸåšã®ç¶æ
ã«å€§ããªåœ±é¿ãäžããŠããŸãã 次ã®ãããã¯ã¯ãES2016ãES2017ãããã³ES2018æšæºã®æ©èœã§ãã
芪æãªãèªè
ïŒ ES6æšæºã®ã©ã®é©æ°ãæã圹ç«ã€ãšæããŸããïŒ