JavaScript(ES2015ïŒES6ïŒ) ãProgateðŠïŒã³ã©ã ãES6ã®éçºç°å¢ãçšæãããïŒïŒmacOSïŒãïŒã
ãã¥ãŒããªã¢ã«ã§ãè¿œå åŠç¿ïŒã©ã¹ãã¹ïŒã«æã¿ãŸãðŠ¹ââïžðŠžââïžâš
ãES6ã®éçºç°å¢ãçšæãããïŒïŒmacOSïŒã
ðžèªèº«ã®PCã§éçºããç°å¢âããŒã«ã«ç°å¢
ãéçºç°å¢ãçšæããããšãâç°å¢æ§ç¯
ã
ðžç°å¢æ§ç¯
ãES6ãããŒã«ã«ç°å¢ã§éçºããããã«å¿
èŠãªãã®
ãâããã¹ããšãã£ã¿
ããã¿ãŒããã«ïŒâ»æšæºè£
åâïžïŒ
ããââ ïžãThe default interactive shell is now zsh.ãã®èŠåæ
ãããããbachãzshã«ããïŒãšããèŠåæãæ¶ãæ¹æ³ïŒïŒ
ãããããâââ
$ echo "export BASH_SILENCE_DEPRECATION_WARNING=1" >> .bash_profile
ãã£ãšç¢ºèªãããšãããã¶ã£ã¡ããé£ããã£ãã®ã§ããããèŠãŠã¿ãã
ðžHomebrew
ãnodebrewããšããnode.jsã®ããŒãžã§ã³ç®¡çããŒã«ãã€ã³ã¹ããŒã«ãã
ããã«ïŒ
ãHomebrewããšããããŒã«ãå
ã«ã€ã³ã¹ããŒã«ãã
ïŒãHomebrewããçšããŠãnodebrewããã€ã³ã¹ããŒã«ããïŒ
ãæåã¯ããThe default interactive shell is now zsh.ãã§ãã ã衚瀺ã§ããŸãããããã¿ãããªæãã ã£ãã®ã«ãHomebrewã®ã€ã³ã¹ããŒã«æ瀺ãããé端ã«ã¬ã³ã¬ã³é 匵ã£ãŠãããŠãŠâŠ ã£ãŠããã³ã³ãã¥ãŒã¿ãŒã£ãŠãããŒãªããšæ¹ããŠæã£ããããŠâŠ èŠå ¥ã£ãŠããŸã£ãã
Homebrew 2.4.9
Homebrew/homebrew-core (git revision 8a79e1;
ã®éãã¯ãããã©âŠ ä»ã¯çœ®ããšããããããâŠð
ðžnode.js
ãâãµãŒããŒãµã€ãã®JavaScriptå®è¡ç°å¢
ãâmacOSã«ã€ã³ã¹ããŒã«ããããšã§ãããŒã«ã«ç°å¢ã«ãŠES6ãå®è¡ã§ãã
ãâããŒãžã§ã³ç®¡çããŒã«ãã€ããããšã§ãè€æ°ã®node.jsã®ããŒãžã§ã³ãç°¡åã«åãæ¿ããããïŒðïŒ
ã€ã³ã¹ããŒã«ã«10å以äžãããããšãããããšããã®ã§ç± ããŠãããŸãããã10ç§çšã§çµãããŸããðâïž
ã€ã³ã¹ããŒã«ã倧äžå€«ãªããã§ãã
ä»æŽã§ãããä»æ¥ã®æ°åã¯ãç·ãã¡ããã§ãð±âš
ânodebrewçµç±ã§node.jsãã€ã³ã¹ããŒã«
2018幎11ææç¹ã®å®å®ç(stable)ã¯v 10.14.1ïŒProgateæ§ïŒ
â2020幎7æçŸåšãããããããã v 14.6.0
ãŸããã€ã³ã¹ããŒã«ã®éã«bashãšzshã®å¯Ÿå¿ãåããŠãã¡ãããšæ瀺ããŠããããããâŠç¥ã£âš
ðžnpm
ãânode.jsã®ããã±ãŒãžç®¡çã¢ããª
ããïŒchalkãreadline-syncïŒ
ãâæåã«ã
ããnpmããã±ãŒãžã®ç®¡çãã¡ã€ã«ã§ãããpackage.jsonããäœæ
âães6_sampleããã£ã¬ã¯ããªçŽäžã«ç§»å
ãâ ïžcd â ã¿ãŒããã«ã§äœæ¥ãããã£ã¬ã¯ããªãå€æŽãã
ãããcd es6_sampleããå®è¡
æåããŸããð¥ºâš
次ã®ãAtomãããã®ç¢ºèªã§ã€ãŸããããã£ãã®ã§ãããã解æ¶â
Atomã§ães6_sampleããã£ã¬ã¯ããªã®äžã«ãpackage.jsonããã¡ã€ã«ãã§ããŠããããšãŸã§ç¢ºèªâïž
ðžbabelã®ã€ã³ã¹ããŒã«
ãâæ°ããèŠæ Œã§èšè¿°ãããã³ãŒããES5ãªã©ã®å€ãèŠæ Œã«æžãæãã䟿å©ãªããã±ãŒãžã®ããš
ãâæžãæããããããŒã«ãïŒãã³ã³ãã€ã©
ãâãã®ã€ã³ã¹ããŒã«ã«15åçšæéãããã£ãâŠâ°
ãâbabelã®èšå®çšãã¡ã€ã«ã®äœæ
ãânode.jsã§importãã€ããããã«ã¯babelãªã©ã§ã³ã³ãã€ã«ããå¿
èŠãããã
ãânode.jsã§ãã¡ã€ã«ãå®è¡ããéã¯ãã¿ãŒããã«ã«ãnode ãã¡ã€ã«åããšå
¥åããã
ããããããããããšã©ãã¡ãã»ãŒãžâââ
ãâbabelã§ãã¡ã€ã«ãã³ã³ãã€ã«ãã
ãð¥./node_modules/.bin/babel src --out-dir distð¥
ãã./node_modules/.bin/babel ããããâ babelãåŒã³åºã
ãããããããããããããããããsrcãâ ãsrcããã£ã¬ã¯ããªã®äžã®ãã¡ã€ã«ãã³ã³ãã€ã«å
ãšããŠæå®
--out-dir dist
â ã³ã³ãã€ã«ãããã¡ã€ã«ã®åºåå
ã®ãã£ã¬ã¯ããªããdistãã«æå®
ãâð¥node dist/first.jsð¥
ãããã¡ã€ã«ãåºåããããæåïŒ
ðžbabelãç°¡åã«åŒã³åºã
ãâbabelã䜿ã£ãŠã³ãŒããå€æããã³ãã³ã
ãã./node_modules/.bin/babel src --out-dir dist
ãâpackage.jsonã«ãããã€ããã³ãã³ããç»é²ããâïž
ãâãtestããšããã¿ã¹ã¯ã«ã
ããã "build": "./node_modules/.bin/babel src --out-dir dist"ãã眮ãæããã
ãâã¿ãŒããã«ã§ããbuildããå®è¡
ããð¥npm run buildð¥
ãâæ£åžžã«ã³ã³ãã€ã«
ãâã³ã³ãã€ã«ããããã¡ã€ã«ãå®è¡
ããnode dist/first.js
ãâES6ã®ãã¡ã€ã«ãbabelã䜿ã£ãŠã³ã³ãã€ã«ãã§ããïŒ
ãã
ãããŸããããªãæã®ãã§ãã¯ãªã¹ãã
ð¥èšäºã§æå®ããã³ãŒãã貌ãä»ããããŠããªã
ð¥å
¥åãããã¡ã€ã«åããœãŒã¹ã³ãŒããªã©ã«èª€åè±åããã
ð¥ãã¡ã€ã«ãä¿åãããŠããªã
ð¥èšäºã§æå®ããŠããç®æã«ãã©ã«ããé
眮ãããŠããªã
ð¥ã³ãã³ãã®å
容ãå®è¡ããŠããå Žæãéã
ããŸãšãã
ã©ã¹ãã¹ãã€ã匷ãããŒâŠ
äœããã°ãã£ãŠãéçã¯è»œãäžæ¯ãããã ããªã®ã«ðŠ¹ââïžæ°ä»ããããã£ã¡ãåãããŠããããðª ã°ãã°ããªâŠ ã£ãŠæãã®ã·ãã¥ãšãŒã·ã§ã³ã§ããå£ã®å€ªåçãå
šãèŠããªãææâŠããšãã Progateæ§ã®ç¥ããã²ãŒã·ã§ã³ã«æ²¿ã£ãŠåŒ·ããªã£ãæ°ã§ããèªåã¯ã³ããã®æè¡ãã身ã«ã€ããŠããªããããããªããããïŒïŒïŒãšããäžå®ãéãªããŸãâŠ(ToT)2æé以äžããã£ãæ°ããããâŠ
ãŸãåãã¯ãããªããã ãïŒ
éçããŸããªïŒïŒã£ãŠæãã§ãããäžã€ã®ã³ã©ã ãããŸãâ
ïŒéããŠãªããéããŠãªããéããŠãªãâŠïŒ
ãã®èšäºãæ°ã«å ¥ã£ãããµããŒããããŠã¿ãŸãããïŒ