Slide 1

Slide 1 text

JavaScriptϏϧυ֓࿦ 2019.4.13 @Nkzn / Yukiya Nakagawa Joetsu Tech Meetup

Slide 2

Slide 2 text

whoami • Yukiya Nakagawa / @Nkzn ʢ32ࡀʣ
 ্ӽࢢग़਎ • ΢Υʔλʔηϧגࣜձࣾ@৽ׁࢢ
 ೶ۀ޲͚αʔϏεʮΞάϦϊʔτʯ • AndroidΤϯδχΞˠϞόΠϧدΓJSΤϯδχΞ • ໌೔͸ٕज़ॻయͰຊചͬͯ·͢

Slide 3

Slide 3 text

޷ධൃץத

Slide 4

Slide 4 text

ࠓ೔͸ JSͷϏϧυͷ࿩Λ͠·͢

Slide 5

Slide 5 text

Target • JavaScriptʹͲ͏ͯ͠Ϗϧυ͕ඞཁʹͳ͍ͬͯ Δͷ͔ͬ͘͠Γདྷ͍ͯͳ͍ํ

Slide 6

Slide 6 text

࠷ۙͷJavaScript

Slide 7

Slide 7 text

ϞδϡʔϧػߏͬͯେࣄͰ͢ΑͶ • ϑΝΠϧ͝ͱʹ໊લۭؒΛ෼͚ΒΕΔ • େ͖ͳΞϓϦέʔγϣϯΛখ͞ͳػೳͷू߹ ͱͯ͠࡞Γ΍͘͢ͳΔ ಥવͰ͕͢

Slide 8

Slide 8 text

Plain Old JavaScript (ES5) // app.js Greeter.greet('Bob'); // greeter.js var Greeter = { greet: function(name) { alert("Hello, " + name + "!"); } }; • ϑΝΠϧؒͰ
 ໊લۭؒΛڞ༗ • ؔ਺಺ʹ͔͠
 είʔϓ͕ͳ͍ • ΈΜͳͰ໊લͷ
 औΓ߹͍

Slide 9

Slide 9 text

2017೥9݄ • Chrome 61ͰϞδϡʔϧػߏ͕ϦϦʔε

Slide 10

Slide 10 text

ES6 Modules // greeter.js const greet = (name) => { alert(`Hello, ${name}!`); } export const Greeter = { greet, }; // app.js import {Greeter} from './greeter.js'; Greeter.greet("hoge"); (SFFUFS͔͠ެ։͞Εͳ͍ ʢHSFFUؔ਺͸Ӆṭ͞ΕΔʣ JNQPSUͨ͠ϞδϡʔϧΛ૊Έ߹Θͤͯ ػೳΛ࡞ΕΔ

Slide 11

Slide 11 text

େମͷ࠷৽ϒϥ΢βͰಈ͘ https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/import

Slide 12

Slide 12 text

ΊͰͨ͠ʂ

Slide 13

Slide 13 text

Ͱ͸ͳͯ͘

Slide 14

Slide 14 text

օ͞Μͷखݩͷϒϥ΢βͰ͸ import/exportಈ͖·͔͢ʁ

Slide 15

Slide 15 text

ͨͿΜಈ͖·͢ΑͶ

Slide 16

Slide 16 text

օ͞Μͷ ͓٬͞Μͷϒϥ΢βͰ͸ import/exportಈ͖·͔͢ʁ

Slide 17

Slide 17 text

https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/import

Slide 18

Slide 18 text

ES201xͷ ͋ͷจ๏΍͜ͷจ๏ ͓٬͞Μͷϒϥ΢βͰ ಈ͖·͔͢ʁ

Slide 19

Slide 19 text

const greet = (name) => { alert(`Hello, ${name}!`); } export const Greeter = { greet, }; "SSPX'VODUJPOT 5FNQMBUF-JUFSBMT 4IPSUIBOEQSPQFSUZOBNFT

Slide 20

Slide 20 text

Arrow Functions https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Functions/Arrow_functions

Slide 21

Slide 21 text

Template Literals

Slide 22

Slide 22 text

Shorthand property names https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Object_initializer

Slide 23

Slide 23 text

IE11͕΍͹͍ ʢEdgeͱSafari΋ͪΐͬͱ΍͹͍ʣ

Slide 24

Slide 24 text

WebΞϓϦέʔγϣϯ͕ Ͳͷϒϥ΢β͔Β ΞΫηε͞ΕΔ͔Λ ੍ݶ͢Δ͜ͱ͸೉͍͠ ʢ͋Δఔ౓͸Ͱ͖Δ͚Ͳମݧ͕ѱ͍ʣ

Slide 25

Slide 25 text

Ͳ͏͠Α͏ • ͔ͤͬ͘ྑ͍ݴޠ࢓༷ʹͳ͖ͬͯͨͷʹɺݹ͍ϒϥ΢ βͰಈ͔ͨ͢Ίʹݹ͍JavaScriptͰॻ͘ͷ͸ݏ • WebΞϓϦ͸ෳࡶͳϏδωεϩδοΫΛ࣋ͭ΋ͷ΋ଟ ͍ • Ϟδϡʔϧػߏ΍async/awaitແ͠ͰෳࡶͳϏδωεϩ δοΫΛίʔυ্ʹදݱ͢Δͷ͸ɺ։ൃޮ཰΍อकੑ ͷ໘Ͱ΋ΑΖ͘͠ͳ͍

Slide 26

Slide 26 text

ES201xͰॻ͍ͨίʔυΛ ES5͔͠ಈ͔ͳ͍ϒϥ΢βͰ ಈ͔͍ͨ͠

Slide 27

Slide 27 text

ϓϩάϥϚʔ͕ॻ͍ͨ ϑΝΠϧͷݴޠ࢓༷ͱ ࣮ࡍʹಈ͘ϑΝΠϧͷ ݴޠ࢓༷Λผʹ͍ͨ͠

Slide 28

Slide 28 text

͋ΔϓϩάϥϜϑΝΠϧΛ ϥϯλΠϜϑΝΠϧʹ ม׵͍ͨ͠

Slide 29

Slide 29 text

͜Ε͸ίϯύΠϧ΍Ϗϧυͱ ݺ͹ΕΔ΋ͷͰ͸ʁ JavaScriptΛ Ϗϧυ͢Δͧʂʂ

Slide 30

Slide 30 text

JavaScriptͷϏϧυ

Slide 31

Slide 31 text

JavaScriptͷ3ͭͷΞϓϩʔν • τϥϯεύΠϧ • ґଘੑղܾ • ϙϦϑΟϧ

Slide 32

Slide 32 text

τϥϯεύΠϧ • ʮಈ͘จ๏ʹ͢ΔʯʹಛԽͨ͠෼໺ • ͕͜͜ಘҙͳͷ͕Babelʢ͋ͱTypeScriptʣ • ϑΝΠϧ͸όϥόϥͷ··ʢimportߏจ͸ ͪΐͬͱܗ͕มΘΔఔ౓ʣ

Slide 33

Slide 33 text

https://babeljs.io/repl Babel(presets-es2015)ʹΑΔม׵ Ṗͷάϩʔόϧม਺ʹม׵͞Εͨ ʢ$PNNPO+4࢓༷ͷFYQPSUػߏʣ #FGPSF "GUFS

Slide 34

Slide 34 text

https://babeljs.io/repl Babel(presets-es2015)ʹΑΔม׵ #FGPSF "GUFS Ṗͷάϩʔόϧؔ਺ʹม׵͞Εͨ ʢ$PNNPO+4࢓༷ͷJNQPSUػߏʣ

Slide 35

Slide 35 text

https://babeljs.io/repl Babel(presets-es2017)ʹΑΔม׵ ϒϥ΢βʹશ෯ͷ৴པΛஔ͘৔߹͸͜ΕͰ΋͍͍ #FGPSF "GUFS

Slide 36

Slide 36 text

https://babeljs.io/repl Babel(presets-es2017)ʹΑΔม׵ #FGPSF "GUFS es2017؀ڥͰasync/awaitΛಈ͔͍ͨ͠৔߹͸ ΍͸Γม׵͕ೖΔ BTZODؔ਺Λ ͔ͭͬͯΈͨ

Slide 37

Slide 37 text

TypeScript(tsc)ʹΑΔม׵ #FGPSF "GUFS ※ ઃఆͰม׵ઌͷϞδϡʔϧ࢓༷ʢCommonJS, AMDʣΛબ୒Ͱ͖Δ https://www.typescriptlang.org/play/

Slide 38

Slide 38 text

ґଘੑղܾ • importߏจ΍requireؔ਺ͷ࣮ݱ • ΤϯτϦʔϙΠϯτʢindex.jsʣ͔Βimport΍requireͰ ܨ͕ͬͨϞδϡʔϧΛɺຊ౰ʹ࣮ߦͰ͖ΔΑ͏ʹ͢Δ • ࣮ߦ࣌ʹܨ͛Δ΍ͭɿRequireJSʢAMDܗࣜΛಈ͔ ͢ʣ • Ϗϧυ࣌ʹܨ͛Δ΍ͭɿWebpack/Browserify/Rollup

Slide 39

Slide 39 text

Webpackͷ৔߹ @@XFCQBDL@SFRVJSF@@ ͱ͍͏ؔ਺͕ϞδϡʔϧղܾΛؤுΔ ͻͱͭPS͍͔ͭ͘ͷ +4ϑΝΠϧʹશϑΝΠϧΛ·ͱΊΔ

Slide 40

Slide 40 text

Webpackͷ৔߹ ˞ FWBMͳͷ͸σόοάதͷڍಈͰ
 ͋ͱͰͪΌΜͱͨ͠ίʔυʹͳΓ·͢ ֎෦ϥΠϒϥϦ΍ϓϩμΫτίʔυ͕ SFRVJSFՄೳͳܗͰऔΓࠐ·Ε͍ͯΔ

Slide 41

Slide 41 text

NJOJGZVHMJGZͱ͔͍Ζ͍Ζೖͬͯ ϓϩμΫγϣϯ؀ڥͰ͸͜͏ͳΔ ʢ͜ͷྫ͸UXJUUFSDPNʣ

Slide 42

Slide 42 text

ϙϦϑΟϧ • ଍Γͳ͍ඪ४ϥΠϒϥϦΛJS੡ͷ୅ସ࣮૷Ͱॆ౰ͯ͘͠ΕΔ • Promise΍Object.assign౳͕ແ͔ͬͨࠒͷϒϥ΢βͰ΋ɺಉ౳ ͷಈ͖Λ͢Δಉ໊ͷؔ਺/Ϟδϡʔϧ͕ଘࡏ͢ΔΑ͏ʹؤுΔ • ϒϥ΢βଆʹຊ࣮૷͕͋Δ৔߹͸ຊ࣮૷ͷํΛ࢖͏ • ͕͜͜ಘҙͳͷ͕core-js • @babel/preset-env Ͱྑ͍ײ͡ʹͳΔ͜ͱ͕ଟ͍

Slide 43

Slide 43 text

Babel(presets-es2015) https://babeljs.io/repl #FGPSF "GUFS 1SPNJTF͸ղܾ͞Εͳ͍

Slide 44

Slide 44 text

https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Promise

Slide 45

Slide 45 text

@babel/preset-env + core-js https://babeljs.io/repl 1SPNJTFΛάϩʔόϧείʔϓʹ ొ࿥ͯ͘͠ΕΔ1PMZpMM !CBCFMQSFTFUFOWͷVTF#VJMU*OΦϓγϣϯΛ zVTBHFzʹ͢Δ͜ͱͰɺඞཁͳ1PMZpMM͕ೖΔΑ͏ʹͳΔ

Slide 46

Slide 46 text

padStart΋࢖͑ΔΑ

Slide 47

Slide 47 text

core-js/modules/es.string.pad-start.js 'use strict'; var internalStringPad = require('../internals/string-pad'); var WEBKIT_BUG = require('../internals/webkit-string-pad-bug'); // `String.prototype.padStart` method // https://tc39.github.io/ecma262/#sec-string.prototype.padstart require(‘../internals/export') ({ target: 'String', proto: true, forced: WEBKIT_BUG }, { padStart: function padStart(maxLength /* , fillString = ' ' */) { return internalStringPad( this, maxLength, arguments.length > 1 ? arguments[1] : undefined, true); } }); https://github.com/zloirock/core-js/blob/e3b99db/packages/core-js/modules/es.string.pad-start.js

Slide 48

Slide 48 text

2019೥ͷJavaScriptϏϧυ • Babel / TypeScriptͰτϥϯεύΠϧ͢Δ • Webpack౳ͰґଘੑղܾΛߦ͏ • @babel/preset-envͱ͔ͰϙϦϑΟϧΛೖΕΔ Ͳ͏΍ͬͯʁ ʢ@babel/preset-typescriptͰBabelͰ΋τϥϯεύΠϧͰ͖ΔΑ͏ʹͳͬͨʣ

Slide 49

Slide 49 text

தڃऀҎ্޲͚ webpack.config.jsͱ babel.config.jsͷ ॻ͖ํΛ֮͑Δ

Slide 50

Slide 50 text

Ϗϧυ৬ਓͷே͸ૣ͍

Slide 51

Slide 51 text

ॳڃऀ޲͚ɿ
 ͜ͷล࢖ͬͯॳظԽ͢ΔͱউखʹೖΔ • Create React App
 https://facebook.github.io/create-react-app/ • Angular CLI
 https://cli.angular.io/ • Vue CLI
 https://cli.vuejs.org/ τϥϯεύΠϧ͸ 5ZQF4DSJQUͰ࣮ݱ ઃఆϑΝΠϧΛ৮Βͤͯ΋Β͑ͳ͍έʔε΋͋Δ ৮Γͨ͘ͳͬͨΒεςοϓΞοϓͷλΠϛϯά

Slide 52

Slide 52 text

·ͱΊ • JavaScriptͷϏϧυ͸ॻ͘ݴޠͱಈ͘ݴޠͷဃ཭͔Β ੜ·Εͨ෼໺ • ϊϯϏϧυϞμϯJS͸·ͩ·ͩ͜Ε͔Βʢϗϯτ ͔ʁʣ • ࠓ͙͢։ൃ͢ΔͳΒʮϏϧυ͢ΔJSʯʹ׳Ε͍ͯ͜͏ • ͔͜͜Βઌ͸܅ͨͪͷ໨Ͱ͔֬Ίͯ͘Εʂ