2018年の”JavaScript” 再入門/re-learning-about-js-in-2018
by
pastak
Link
Embed
Share
Beginning
This slide
Copy link URL
Copy link URL
Copy iframe embed code
Copy iframe embed code
Copy javascript embed code
Copy javascript embed code
Share
Tweet
Share
Tweet
Slide 1
Slide 1 text
2018ͷ”JavaScript” ࠶ೖ Pasta-K at KMC SpringCamp 2018
[email protected]
/
[email protected]
Slide 2
Slide 2 text
@pastak
Slide 3
Slide 3 text
• ژେֶֶ෦ใֶՊ ܭࢉػՊֶίʔε5ճੜ • KMC ݩใ • Nota Inc Gyazo։ൃνʔϜ ΞϧόΠτ • JavaScript / React / Ruby on Rails • Browser Extension • גࣜձࣾͯͳ ΞϧόΠτ • TypeScript
Slide 4
Slide 4 text
࣍ • JavaScriptͷྺ࢙ • JavaScriptͱECMAScript • ECMAScriptͷḷ͖ͬͯͨಓͷΓ • babel / browserify / Webpack ...ԿͷͨΊʁ • ·ͱΊ
Slide 5
Slide 5 text
͜ͷτʔΫͷλʔήοτ • JavaScriptʹ͍ͭͯաڈʹ৮Εͨ͜ͱ͕͋Δͷͷɺ͜͜ JavaScriptͷΤίγεςϜʹ৮Ε͍ͯͳ͍ਓ • ࠷ۙͷJavaScriptֶशίετ͕ߴ͍ͱײ͍ͯ͡Δਓ • JavaScriptʹ͍ͭͯೖ͍ͨ͠ͱߟ͍͑ͯΔਓ • ࠓޙJavaScriptΛ͍ͬͯ͘"Մೳੑ͕͋Δਓ
Slide 6
Slide 6 text
͜ͷτʔΫͷΰʔϧ • ʮ࠷ۙͷJavaScriptΛॻͨ͘Ίʹඞཁͳπʔϧ͕ଟֶͯ͘शίε τ͕ߴͯ͘ΫιʯΈ͍ͨͳ͜ͱΛಥવݴ͍ग़ͯ͠͠·Θͳ͍Α͏ ʹ͢Δ • ͱ͜ΖͰԿނ͜Μͳʹ৭ʑπʔϧΒ༷Β͕ʹͳ͍ͬͯ Δͷ͔Λཧͯ͠ཧղ͢Δ • ͱ͜ΖͰͱ͜ΖͰɺ ʮ“JavaScript”ͬͯԿ??ʯΛѲ͢Δ
Slide 7
Slide 7 text
࣍ͷ֤ߦͷίʔυ(ϒϥβ|NodeJS)Ͱಈ͘?
Slide 8
Slide 8 text
͜ͷτʔΫͰ͞ͳ͍͜ͱ • JavaScriptͷจ๏ه๏ɺ࠷ۙՃ͞ΕͨECMAScriptͷ༰ʹ͍ͭͯ • JavaScriptΛ༻͍ͨΞϓϦέʔγϣϯߏஙςΫχοΫ • JSͷςΫχοΫΓ͍ͨਓڈͷय़߹॓ͷࢿྉΛಡΜͰ͘Ε • WebΞϓϦέʔγϣϯͰ 60fpsΛ(ۃྗ)ࢦ͢ // Speaker Deck • https://speakerdeck.com/pastak/webahurikesiyonte-60fpswo-ji-li-mu-zhi-su
Slide 9
Slide 9 text
JavaScriptͷྺ࢙Λ ৼΓฦͬͯΈΔ
Slide 10
Slide 10 text
օ͞Μ͕Πϝʔδ͢ΔJavaScriptͲΕͰ͢? • WebϖʔδΛ͔ʹ͢Δͭ • Google Maps / Web 2.0 / Ajax • Twitter / Facebook / SPA / PWA • NodeJS
Slide 11
Slide 11 text
ॳظͷϢʔεέʔε • WebαΠτΛ՚ඒʹ͢Δ • ͋Μ·ΓศརͳΘΕํ͕ͳ͔ͬͨ • ΫϦοΫͨ͠ΒalertΛग़͢ • จࣈ͕νΧνΧ͢Δ • mouseoverͰcursorΛม͑Δ
Slide 12
Slide 12 text
JavaScript҉ࠇ࣌ • 2000લJSͷ੬ऑੑΛͭ͘ΣϒαΠτଟ͘JavaScript ΛແޮԽ͍ͯ͠Δਓͨͪଟ͍ͨ͘ • ϒϥΫϥ • Flashશظ
Slide 13
Slide 13 text
2005 Google Mapsര • Google MapsແݶʹεΫϩʔϧͰ͖ΔਤαΠτͩͬͨ • ྫ͑Yahoo!ͷਤ্ԼࠨӈʹҠಈ͢ΔϦϯΫΛԡͯ͠Ҡಈ͍ͯͨ͠ • Google Maps͜ͷͱ͖XMLHttpRequestͳͲΛͬͯμΠφϛοΫʹಡ ΈࠐΈΈΛఏڙ͍ͯͨ͠ • AjaxΞϓϦέʔγϣϯ͕ਓؾΛത͢Δ͖͔͚ͬʹͳͬͨ
Slide 14
Slide 14 text
ਓʑ ؾ͍ͨ
Slide 15
Slide 15 text
JavaScript ศར͡ΌΜ
Slide 16
Slide 16 text
JavaScriptʹର͢ΔೝࣝͷมԽ • WebαΠτΛ૽͕͘͢͠Δ͚ͩͷअຐͳଘࡏͩͱࢥΘΕ͍ͯͨ • ࣮ࡍɺJavaScriptΛUXʹܨ͛ΔΑ͏ͳΞϓϦέʔγϣϯ͕ͳ͔ͬͨ • DynamicHTMLͷඇޓඇಉظ௨৴ΛNN͕ͳ͔ͳ͔࣮͠ͳ͔ͬ ͨ͜ͱ͋Δ͕ɾɾɾ • ࣮ྫͱͯ͠ͷGoogle MapsϢʔβʔ͚ͩͰͳ͘։ൃऀʹେ͖ͳӨڹΛ༩ ͑ͨ
Slide 17
Slide 17 text
JSͰϚογϡΞοϓ͢Δͷ͕ྲྀߦͬͨ • Google Maps Ajax APIΛ࢝Ίͱ͢ΔXMLΛఏڙ͢ΔAPIjsonpΛఏڙ͢ ΔAPI͕৭ʑͱొ • ͜ΕΒΛΈ߹ΘͤͯΞϓϦέʔγϣϯΛ࡞ΔʰϚογϡΞοϓʱ͕ྲྀߦ • ͜ͷྲྀΕΛਵ͢ΔϦονͳWebΞϓϦέʔγϣϯ͕ొ࢝͠ΊΔ • ʰWeb 2.0ʱ
Slide 18
Slide 18 text
ϒϥβߴԽ • 2008 Google Chromeͷొ • GoogleۘJSΤϯδϯ V8͕͔ͬͨ • ଞͷJSΤϯδϯਵͯ͠ߴԽͷಓ • ͜Μͳʹ͘Ͱ͖ΔͳΒͬͱΞϓϦέʔγϣϯͷػೳΛدͤΕΔ ͧ
Slide 19
Slide 19 text
NodeJSొ • 2009 V8Λར༻ͨ͠αʔόʔαΠυ্ͷJavaScript࣮ߦڥͱͯ͠ొ • ΠϕϯτۦಈܕʹΑΔϊϯϒϩοΩϯάIOͳͲʹ͕ू·ͬͨ • ʰΫϥΠΞϯτ1ສʱ͕ى͖ͳ͍ • ͔͜͜ΒҰؾʹJSϒϥβ্Ҏ֎Ͱಈ͘ϓϩάϥϛϯάݴޠʹ • ͦΕҎલಈ͔͢ڥ͕͋ͬͨ͋·ΓϝδϟʔʹͳΒͳ͔ͬͨ • ࠓαʔόʔαΠυͪΖΜɺCLI༻ͷεΫϦϓτπʔϧΛॻͨ͘Ίʹଟ͘ར༻͞Ε͍ͯΔ
Slide 20
Slide 20 text
ݱࡏͷJavaScriptΞϓϦέʔγϣϯ • AngularReactɺVueͳͲΛͬͨSPAΞϓϦέʔγϣϯ • pushStateʹΑΔཤྺॻ͖ࠐΈ + XHR/fetchʹΑΔσʔλऔಘ • Progressive Web Application • ϞόΠϧϒϥβͰσεΫτοϓϒϥβͰ͍͍ײ͡ʹಈ͘ • ΦϑϥΠϯΩϟογϡɾϩʔΧϧετϨʔδ
Slide 21
Slide 21 text
JavaScriptͱECMAScript
Slide 22
Slide 22 text
ECMAScriptͱԿ͔
Slide 23
Slide 23 text
·ͣ”ECMAScript”Λͬ͘͟Γͱ • JavaScriptͷඪ४༷ͷ໊শ • Ecma Internationalͷtc39Ͱٞ͞Ε͍ͯΔ • ݱࡏLiving StandardͷܗͰͲΜͲΜ༷͕Ճ͞Ε͍ͯΔ
Slide 24
Slide 24 text
JavaScriptॳظ • 1995 NetScapeʹͤΔͨΊʹ։ൃ͞ΕΔ • Java͕ྲྀߦ͍ͬͯͨͷͰɺ໊લΛआΓ͖ͯͯJavaScriptʹ • 1996 IE3.0ʹͤΑ͏ͱ͢Δަবࣦഊ • Microsoft͕ಠࣗͷJScriptͱͯ͠։ൃ
Slide 25
Slide 25 text
JavaScriptඪ४Խ • 1997 JavaScriptͱJScriptͷ྆ํ͕͋Δঢ়گΛͳΜͱ͔͠Α͏ͱ͍͏ Ϟνϕʔγϣϯ͕Netscapeʹ͋ͬͨ • ͜ͷJavaScriptͷඪ४ԽΛECMAΠϯλʔφγϣφϧʹґཔ • ECMA-262ͷॳ൛͕ग़དྷΔ • “JavaScript”ඪͷ߹Ͱ͑ͳ͍ͷͰɺ”ECMAScript”ʹ
Slide 26
Slide 26 text
ECMAScriptඪ४Խͷܥේ • 1998 ECMA-262 ୈ2൛ • 1999 ECMA-262 ୈ3൛ • ͜͜·Ͱॱௐͩͬͨɾɾɾ
Slide 27
Slide 27 text
ECMAScriptඪ४Խͷܥේ • 1998 ECMA-262 ୈ2൛ • 1999 ECMA-262 ୈ3൛ • ͜͜·Ͱॱௐͩͬͨɾɾɾ • ECMA-262 ୈ4൛Ͱࣄ݅ىͬͨ͜!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Slide 28
Slide 28 text
ECMAScript 4Ͱͷग़དྷࣄ • ਪਐ • Adobe, Mozilla(چNetscape Navigationࣾ), Opera, Google • ଟ͘ͷ৽ػೳΛऔΓࠐΈJavaScriptΛେ෯ʹมߋ͢Δ • ର • Microsoft & Yahoo • ES3ΛϕʔεʹػೳՃόάमਖ਼ΛؚΜͩES3.1ͱͯ͠ެ։͢Δ
Slide 29
Slide 29 text
ECMAScript4ͱͳΜͩͬͨͷ͔ • ߏཁૉᶃ • ActionScript 3.0(Adobe͕FlashΞϓϦέʔγϣϯͷͨΊʹ։ൃ͠ ͍ͯͨϓϩάϥϛϯάݴޠ)͔ΒऔΓࠐΜͩػೳ • class, interface, ܕ, ໊લۭؒ, package ͳͲ
Slide 30
Slide 30 text
ECMAScript4ͱͳΜͩͬͨͷ͔ • ߏཁૉᶄ • JavaScript 1.7(NNFirefoxʹࡌ͍ͬͯͨJS࣌JavaScript 1.X ͱ͍͏όʔδϣϯ൪߸͕߱ΒΕ͍ͯͨ)͔ΒऔΓࠐΜͩػೳ • let, ׂೖ, δΣωϨʔλʔ ͳͲ
Slide 31
Slide 31 text
ECMAScript4ͱͳΜͩͬͨͷ͔ • ߏཁૉᶅ • ͦͷଞʹଟ͘ͷ৽ͨͳػೳΛऔΓࠐΉ͜ͱ͕ըࡦ͞Ε͍ͯͨ • ྫ͑ɾɾɾ
Slide 32
Slide 32 text
ςϯϓϨʔτ • C#ͰGenericͱݺΕͯΔͭ http://tech.nitoyon.com/ja/blog/2007/10/30/es4-overview/ ΑΓ
Slide 33
Slide 33 text
ԋࢉࢠΦʔόʔϩʔυ http://tech.nitoyon.com/ja/blog/2007/10/30/es4-overview/ ΑΓ
Slide 34
Slide 34 text
ECMAScript4ʹؔ͢Δܾண • ݁Ռͱͯ͠ES3.1 (aka ES Harmony)Λ͍ͬͯ͘͜ͱʹऩଋ (20088݄) • ES4͜Ε·ͰͷESʹରͯ͠มߋ͕େ͖͗͢ΔͷͰԺʹΓ͍ͨ • จ๏ͷޓੑͷͳͲ͔ΒաڈͷWebͷࢿ࢈ʹӨڹΛ༩͑ͯ͠·͍͔Ͷͳ͍ • ໊લۭؒύοέʔδͳͲWebʹ͙ͦΘͳ͍ͷͰɺES3.1ͷٞͷ্ͰҰѻ Θͳ͍ • ͦΕҎ֎ͷػೳʹ͍ͭͯٞͷରͱͯ͠ѻ͏
Slide 35
Slide 35 text
ECMAScript5ϦϦʔε • ES Harmonyͱͯ͠ਐΊΒΕ͍ͯͨ࡞ۀʹ2009ɺES5ͱͯ͠Ϧ Ϧʔε͞Εͨ • ϝδϟʔόʔδϣϯ͕2্͕͍ͭͬͯΔ͕࣮ଶ3.0͔Β3.1ͷϚΠ φʔόʔδϣϯΞοϓ • Mozilla͕ਐΊ͍ͯͨJavaScript 1.X → 2.0ͷ࡞ۀESʹ४ڌ͢Δํ ʹͳΓɺ͜ͷόʔδϣϯݺশߦΘΕͳ͘ͳͬͨ
Slide 36
Slide 36 text
ECMAScript 5ͷ৽ػೳ • JSON.parse, JSON.stringify ͷՃ • ArrayͷϝιουͷՃ forEach, filter, map, reduce, indexOf • StringͷϝιουͷՃ trim • StrictϞʔυͷՃ ͳͲ
Slide 37
Slide 37 text
تͷECMAScript6ϦϦʔε • 2015ϦϦʔε • ଟ͘ͷັྗతͳػೳ͕༷ʹͳͬͨ!!!!!!!!!!!!!!!!!!! • Θ͍Θ͍
Slide 38
Slide 38 text
arrow function • () => {} ͰؔࣜΛॻ͚Δ • this͕ͦͷએݴ࣌ͷίϯςΩετͷthisʹଋറ͞ΕΔ
Slide 39
Slide 39 text
enhanced object literals / destructuring • Objectͷkey͕ม໊ͱಉ࣌͡ʹলུՄೳ • ArrayͱObjectͰׂೖ͕Մೳʹ
Slide 40
Slide 40 text
Promise • JSͷίʔϧόοΫࠈ͔ΒਓʑΛղ์ • ͦΕ·ͰਓʑjQuery.defferͱ͔ʢyieldͱ͔ʣͰࣃΛ৯͍ͬ͠ ͍ͯͨͷ͡Ό
Slide 41
Slide 41 text
Class • ͦΕ·ͰਓʑprototypeΛར༻͍͍ͯͬͯͬͯͨ͠
Slide 42
Slide 42 text
Class • ES6ͰClassߏจ͕Ճ͞Εͨ
Slide 43
Slide 43 text
ͦͷଞ • Symbol • Number.isNaN • Array.from / Array.find • String.includes / String.repeat • Object.assign • ඌ࠶ؼ࠷దԽ
Slide 44
Slide 44 text
ES6➜ES2015…ͦͯͦ͠ͷઌ • ES6ES2015ʹվশɻҎ߱Living Standardํࣜʹ • ECMAScriptͷ༷ॻͷυϥϑτGithub্ͷtc39/ecma262Ͱཧ͞Ε͍ͯΔ • ࠷৽ͷECMAScript༷ https://tc39.github.io/ecma262/ • ຖ۠ΓΛ͚ͯҎ߱ES2016, ES2017ͱTagΛ͚Δ • ͜ͷλΠϛϯάͰStage4ʹೖ͍ͬͯΔ༷Λରʹ͢Δ
Slide 45
Slide 45 text
http://azu.github.io/slide/2018/node/ecmascript39.html ΑΓ
Slide 46
Slide 46 text
ࠓͷECMAScript • ͦΕ·Ͱશͯͷ༷͕߹ҙ͞ΕͨޙʹϦϦʔε͞Ε͍͕ͯͨɺݱ ࡏͷES߹ҙ͕औΕ༷͔ͨΒॱ࣍ϦϦʔε͞Ε͍ͯΔ • ྫ͑ɺES4ͷ߹ҙܗͷࣦഊʹΑΓES3͔Β࣍ظόʔδϣϯͰ͋ ΔES5·Ͱʹ10ʢES4ࣗମʹ2.5͘Β͍ͷϦιʔε͕͔͔ͬ ͍ͯͨͱݴΘΕ͍ͯΔ)͕͔͔ͬͨ
Slide 47
Slide 47 text
ࠓͷECMAScript • Github্ͷେ͖ͳϓϩδΣΫτͱ͍͏ܗͰਐΊ͍ͯΔ • ϑΟʔυόοΫΛΑΓड͚͍͢ڥʹ • ϒϥβϕϯμʔ͚ͩͰͳ͘JavaScriptΛར༻͢Δ։ൃऀ͔Β ϑΟʔυόοΫΛΑΓड͚ΔͨΊʹ • ϓϩηεͷಁ໌Խ • ϛʔςΟϯάϊʔτશͯGithub্Ͱެ։͞Ε͍ͯΔ
Slide 48
Slide 48 text
ECMAScriptͷݱࡏͷࡦఆखॱ • ͦΕͧΕͷػೳʹ͍ͭͯݸผͷϓϩϙʔαϧͱͯ͠ਐΊΔ • ͜ͷϓϩϙʔαϧٞͷͨΊʹ࠷େ࠷খݶͷܗͷͷ͕૿͑ͨ • ऀ(νϟϯϐΦϯ)ͱstage0ʙ4͕͋Γɺstage4ʹͳΔͱ ECMAScriptͷ༷ʹmergeՄೳʹͳΔ
Slide 49
Slide 49 text
ECMAScriptϓϩϙʔαϧͷStageʹ͍ͭͯ http://azu.github.io/slide/2018/node/ecmascript39.html ΑΓ
Slide 50
Slide 50 text
ECMAScriptϓϩϙʔαϧͷStageʹ͍ͭͯ stage3͔Βstage4ʹ ʲ2ͭҎ্ͷ࣮*ʳ͕ඞཁ * flag͖࣮ͰOK
Slide 51
Slide 51 text
TranspilerPolyfillʹ͍ͭͯ • Transpiler: ৽͍͠ߏจΛطଘͷػೳͰ࠶ݱͰ͖ΔΑ͏ʹιʔείʔυΛม ͢Δπʔϧ • ex: Babel • Polyfill: ϓϩϙʔβϧͰՃ͞Εͨ৽͍͠ϝιουؔͳͲΛ࣮Λఏ ڙ͢ΔϥΠϒϥϦ • ex: babel-polyfill, whatwg-fetch
Slide 52
Slide 52 text
TranspilerPolyfillʹ͍ͭͯ • TranspilerPolyfill৽͍͠ߏจϝιουͳͲͷ࠶ݱΛࢼΈ͍ͯ Δ͚ͩͰɺ෦తͳৼΔ͍࣮ߦʹ͍࣮ͭͯࡍͷϒϥβ ࣮ͱҟͳΔͷͰҙ • ϒϥβຊମͷ࣮Λͨͣͯ͠ઌߦͯ͠ࢼ͢͜ͱ͕ग़དྷΔͷͰɺ ϓϩϙʔαϧͷϑΟʔυόοΫ͕༰қʹͳͬͨ
Slide 53
Slide 53 text
ECMAScriptݱঢ়·ͱΊ • ES5·Ͱશ༷ʹ͍ͭͯಉҙͷ্ͰϦϦʔε͍ͯͨ͠ • ES6 (= ES2015)Ҏ༷߱ຖʹಉҙ͕ͳ͞ΕΔͱϦϦʔε • ࣮͕2ͭҎ্ଘࡏ͍ͯ͠Δɾςετ͕͋Δ • tc39ٕज़ҕһձͰͷঝೝ • ຖ6݄ࠒʹESXXXXͱศٓతͳ໊લ(λά)͕͚ΒΕΔ
Slide 54
Slide 54 text
JavaScriptͱECMAScript
Slide 55
Slide 55 text
“JavaScript”ͱ”ECMAScript"
Slide 56
Slide 56 text
“JavaScript”ͱ”ECMAScript" ͔͜͜Β͕ຊ!!!!!!!!!!
Slide 57
Slide 57 text
JavaScriptͷॲཧܥ • ϒϥβʹࡌ͍ͬͯΔΤϯδϯͨͪ • Chrome: V8, Safari: JavaScriptCore, Firefox: SpiderMonkey ͳͲ • CLI্ͳͲͰར༻Ͱ͖Δॲཧܥ • NodeJS
Slide 58
Slide 58 text
օ͞Μͷॻ͍͍ͯΔ”JavaScript”ʁ
Slide 59
Slide 59 text
օ͞Μͷॻ͍͍ͯΔ”JavaScript”ʁ Perl????
Slide 60
Slide 60 text
օ͞Μͷॻ͍͍ͯΔ”JavaScript”ʁ ES5 strict mode
Slide 61
Slide 61 text
"use strict" / Opt-in Strict mode • JavaScriptجຊతʹޙํޓੑΛഁյ͠ͳ͍Α͏ʹ։ൃ͕ਐΊΒΕͯ ͖ͨ • ES5ͷStrict modeաڈͷJSͷෛ࠴ͷฦ٫ɺকདྷͷJSͷࢿͷͨΊ • ߏจϥϯλΠϜͷৼΔ͍ʹରͯ͠มߋΛՃ͑Δ • ϑΝΠϧͷઌ಄·ͨؔͷઌ಄Ͱ
Slide 62
Slide 62 text
"use strict" / Opt-in Strict mode • JavaScriptجຊతʹޙํޓੑΛഁյ͠ͳ͍Α͏ʹ։ൃ͕ਐΊΒΕͯ ͖ͨ • ES5ͷStrict modeաڈͷJSͷෛ࠴ͷฦ٫ɺকདྷͷJSͷࢿͷͨΊ • ߏจϥϯλΠϜͷৼΔ͍ʹରͯ͠มߋΛՃ͑Δ • ϑΝΠϧͷઌ಄·ͨؔͷઌ಄Ͱ ߏจΛՃ͢ΔͷͰͳ͘จࣈྻΛࣝผ ʹར༻͢Δ͜ͱͰඇରԠͷڥͰͦΕ ͳΓʹಈ͘Α͏ʹͳ͍ͬͯΔ (ͨͩ͠ৼΔ͍͕ҟͳΔͷͰҙਤ௨Γ ʹಈ͔ͳ͍͜ͱ͕ଟ͍ͷͰҙ)
Slide 63
Slide 63 text
Strict modeͰมΘΔ͜ͱ • ۮൃతͳάϧʔόϧมͷೖΛΤϥʔʹ • ͍͔ͭ͘ͷ߹ʹTypeError ྫ֎͕ൃੜ͢ΔΑ͏ʹʢҎԼͦͷྫʣ • NaN ͷೖ • JSͰ NaN ΩʔϫʔυͰͳ͘άϧʔόϧม • getterϓϩύςΟͷೖ • ΦϒδΣΫτʹॏෳͨ͠ϓϩύςΟΛઃఆ͢Δ
Slide 64
Slide 64 text
Strict modeͰมΘΔ͜ͱ • implementsɺinterfaceɺletɺpackageɺprivateɺprotectedɺpublicɺstaticɺyield Λ༧ޠʹՃ • with Λ͏ͱSyntax Errorʹ • thisͷৼΔ͍ͷมߋ • τοϓϨϕϧ·ͨؔҎ֎ͰͷؔએݴΛΤϥʔʹ ͳͲ
Slide 65
Slide 65 text
this in JS • JavaScriptͷthisͦΕ͚ͩͰ1ͷຊ͕ॻ͚Δ͘Β͍৭ʑͳ͕ ͋Δ
Slide 66
Slide 66 text
this in JS • JavaScriptͷthisͦΕ͚ͩͰ1ͷຊ͕ॻ͚Δ͘Β͍৭ʑͳ͕ ͋Δ From http://efcl.info/2018/01/04/what-is-this/
Slide 67
Slide 67 text
this in JS • JavaScriptͷthisͦΕ͚ͩͰ1ͷຊ͕ॻ͚Δ͘Β͍৭ʑͳ͕ ͋Δ From http://efcl.info/2018/01/04/what-is-this/
Slide 68
Slide 68 text
this in JS • JavaScriptͷthisͦΕ͚ͩͰ1ͷຊ͕ॻ͚Δ͘Β͍৭ʑͳ͕ ͋Δ • JSΛॻ͍͍ͯΔͱͱʹ͔͘thisͰϋϚΔɻ͜ΕͰ͔ͱϋϚΔɻ • ࠷ۙΞϩʔؔͳͲͷ͓ӄͰϚγʹͳͬͨ
Slide 69
Slide 69 text
օ͞Μͷॻ͍͍ͯΔ”JavaScript”ʁ ES6 spread parameter
Slide 70
Slide 70 text
օ͞Μͷॻ͍͍ͯΔ”JavaScript”ʁ jQuery
Slide 71
Slide 71 text
jQuery • ΈΜͳେ͖jQuery • JSjQueryΛ༻͍ͨͷ͔͠ॻ͍ͨ͜ͱͳ͍ਓଟ͍͔? • $$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Slide 72
Slide 72 text
jQueryͱJavaScript • JS͕DOMૢ࡞ʹΑΔUIߏஙͳͲͷϋʔυϧ͕ҰؾʹԼ͕ͬͨ • ϝιουνΣʔϯͰॻ͚Δͷਓؾͩͬͨ • jQueryϓϥάΠϯΛར༻ͨ͠Ξχϝʔγϣϯ৭ʑͳύʔπ(ྫ͑lightbox)Λར༻ ͨ͠WebαΠτ͕രൃతʹ૿͑ͨ • jQuery mobileͱ͍͏ϞόΠϧରԠͤ͞Δͷ͋ͬͨ • WebαΠτͰෳͷϓϥάΠϯΛͬͨΓɺUIຖʹ৭ʑͳίʔυΛॻ͍ͯఏڙ͢Δͱ ͍͏͜ͱҰൠతʹͳͬͨ
Slide 73
Slide 73 text
ͦͷଞͷஶ໊ͳJavaScriptϥΠϒϥϦ • Backbone.js • prototype.js • YUI Library • AngularJS • React • VueJS
Slide 74
Slide 74 text
2009:AngularJS 2005: prototype 2006: jQuery 2014:Vue 2010:Backbone 2013:React
Slide 75
Slide 75 text
օ͞Μͷॻ͍͍ͯΔ”JavaScript”ʁ DOM API
Slide 76
Slide 76 text
DOM APIͬͯԿʁ • DOM(Document Object Model)XML, HTML, SVGυΩϡϝϯτΛ ϓϩάϥϛϯάݴޠͰར༻͢ΔͨΊʹϞσϧԽͨ͠ͷ • จॻΛߏͰදݱ͍ͯ͠Δ • ϊʔυ͞ΒʹΠϕϯτϋϯυϥΛ͍࣋ͬͯΔ • ଟ͘JavaScriptͰར༻͞ΕΔ͕ɺDOMECMAScriptͷ༷ͷҰ ෦Ͱͳ͍
Slide 77
Slide 77 text
DOM APIͬͯԿʁ • Q: DOM APIʹ͍ͭͯͷ༷ͲͷஂମʹΑͬͯࡦఆ͞Ε͍ͯΔʁ
Slide 78
Slide 78 text
DOM APIͬͯԿʁ • Q: DOM APIʹ͍ͭͯͷ༷ͲͷஂମʹΑͬͯࡦఆ͞Ε͍ͯΔʁ • A: W3C, WHATWG
Slide 79
Slide 79 text
DOM APIͬͯԿʁ • Q: DOM APIʹ͍ͭͯͷ༷ͲͷஂମʹΑͬͯࡦఆ͞Ε͍ͯΔʁ • A: W3C, WHATWG • HTMLͷ༷ࡦఆͷํͷҧ͍ͰᦻΛ͔ͭ͜ͱʹͳͬͨ2ͭͷஂ ମ͕ͦΕͧΕ༷Λ༗͍ͯ͠Δ • WHATWGͰDOM Standard, W3CͰDOM 4 • جຊతʹಉ͕ͩ͡Ұ෦͕ࠩ͋Δ
Slide 80
Slide 80 text
༨ஊ: W3CͱWHATWG • 1999ͷHTML4.01קࠂҎ߱ɺHTMLͷΞοϓσʔτ͕ࢭ·͍ͬͯͨ • 2004 Apple, Opera, MozillaͰWHATWGઃཱ • 2007 ྆ऀ͕ڠྗମ੍ΛऔΔW3C HTML Working GroupΛઃཱ • 2012 קࠂΛઃཱ͍ͨ͠W3Cͱ։ൃͷܧଓΛॏࢹ͢ΔWHATWG͕ᦻΛ͔ͭ͜ͱʹ ͳΓɺ྆৫͕ผʑʹࡦఆ࡞ۀΛਐΊ͍ͯ͘͜ͱʹ • 2014 W3C HTML 5קࠂ͕ൃߦ
Slide 81
Slide 81 text
༨ஊ: W3CͱWHATWG • WHATWGͷDOM (Living) Standard • ϒϥβϕϯμʔWHATWGͷվగʹूத͍ͯ͠Δ • W3C͜ΕΒΛίϐʔ͢Δ͚ͩͰͳ͘Ұ෦ՃචΛͯ͠ဃΛ࢈ΜͩΓ͍ͯ͠Δ ͜ͱʹରͯ͠൷͕͋Δ • ͨͩW3CͷจॻϩΠϠϦςΟʔϑϦʔ͕໌ه͞Ε͍ͯͨΓɺઐՈʹΑΔϫ ΠυϨϏϡʔ͕ͳ͞Ε͍ͯΔ(ͱ͍͏ͷ͕ओுͰ͋Δ)
Slide 82
Slide 82 text
ಉ͘͡ECMAScriptͷ༷ʹؚ·Εͳ͍ͷ • window • window.navigator • window.location • window.history • XMLHttpRequest • HTML Canvas 2D Context • WebStorage ...etc HTML Living Standardʹ ؚ·Ε͍ͯΔ
Slide 83
Slide 83 text
օ͞Μͷॻ͍͍ͯΔ”JavaScript”ʁ ES module
Slide 84
Slide 84 text
JavaScriptͰ֎෦ϥΠϒϥϦΛಡΈࠐΉ • ౷తͳJavaScriptͷϥΠϒϥϦͷಡΈࠐΈํ
Slide 85
Slide 85 text
JavaScriptͰ֎෦ϥΠϒϥϦΛಡΈࠐΉ • scriptλάͰಡΈࠐΉख๏ͷ • window(άϩʔόϧ)Λհͯؔ͠Λڞ༗͢Δඞཁ͕͋Δ • άϩʔόϧྖҬͷԚછ • ར༻ॱΛߟ͑ͯɺॱ൪ʹλάΛهड़͢Δඞཁ͕͋Δ • ෳͷϑΝΠϧΛಡΈࠐΉඞཁ͕͋Δ • ಉҰΦϦδϯͷಉ࣌ଓ੍ݶ
Slide 86
Slide 86 text
֎෦ϥΠϒϥϦಡΈࠐΈͱ͖߹͏ • JSͷߏจͱͯ͠֎෦ϥΠϒϥϦΛಡΈࠐΉํ๏Λఏڙ͢Δ͜ͱͰ άϩʔόϧڥΛར༻ͨؔ͠ͷڞ༗ΛࢭΊΔ • ࣄલʹͦΕΒͷϥΠϒϥϦΛؚΜͩঢ়ଶͰ1ͭͷϑΝΠϧʹίϯύ Πϧ͢Δ͜ͱͰଓϑΝΠϧαΠζͷΛղܾ͢Δ
Slide 87
Slide 87 text
JavaScriptͱpackage maneger • ֎෦ͷϥΠϒϥϦΛޮΑ͘ཧ͢ΔͨΊʹύοέʔδϚωʔδϟ ͕ඞཁͰ͋ͬͨ • ͦͷͨΊʹొͨ͠ͷ͕ • bower • npm
Slide 88
Slide 88 text
JavaScriptͱpackage maneger • JavaScriptͷpackage manager • bower • ϒϥβ͚ͷϥΠϒϥϦΛఏڙ͍ͯͨ͠ • 2014ޙ͘Β͍͔ΒJSք۾͔Βෛ࠴ͱͯ͠ೝࣝ͞Ε͍ͯͨ • npm • Node͚ͷϥΠϒϥϦΛఏڙ͍͕ͯͨ͠ɺϒϥβ͚ͷϥΠϒϥϦѻ ͏Α͏ʹͳͬͨ • 20147݄ʹjQuery͕npmͷΈͰbowerͷαϙʔτΛऴྃͨ͠ • https://github.com/jquery/jquery/pull/1620
Slide 89
Slide 89 text
require vs import • CommonJS • module.exportsʹೖ͢Δ͜ͱͰॻ͖ग़͠ • require()Λར༻ͯ͠ಡΈࠐΈ • ECMAScript • exportࣜΛར༻ͯ͠ॻ͖ग़͠ • importࣜΛར༻ͯ͠ಡΈࠐΈ
Slide 90
Slide 90 text
#
Slide 91
Slide 91 text
͋Εʁզʑ ECMAScriptܗࣜ ͡Όͳ͍ͷΛ ͣͬͱͬͯͨͷʁ
Slide 92
Slide 92 text
ͳͥ require ͕ΘΕ͍ͯͨͷ͔ • ES2015ͷͱ͖ʹγϯλοΫεͷΈΛܾΊ͍ͯͨ • ࣮ࡍʹॲཧܥ͕ͲͷΑ͏ʹϞδϡʔϧͷಡΈࠐΈΛߦ͏͔ʹ͍ͭͯECMAScriptͰఆٛ͞ Ε͍ͯͳ͔ͬͨ ➜ NodeJS: NodeJSਞӦ ➜ϒϥβ: WHATWG • ͲͷΑ͏ͳৼΔ͍Ͱ࣮͢Δ͔Λ֤ਞӦ͕ܾఆ͢Δඞཁ͕͋ͬͨͷͰɺ༷ʹΑͬͯ શͯ
Slide 93
Slide 93 text
۩ମతʹͲ͏͍͏͕͋ͬͨͷ͔ • ϩʔυ࣌ʹͦͷϑΝΠϧ͕ESM͔Ͳ͏͔ΛΔඞཁ͕͋Δ • ࣝผࢠ(URI)ΛͲͷΑ͏ʹղܾ͢Δ͔ • طଘͷCommonJSͱͷޓੑΛͲ͏͢Δ͔(NodeJS)
Slide 94
Slide 94 text
۩ମతʹͲ͏͍͏͕͋ͬͨͷ͔ https://teppeis.hatenablog.com/entry/2017/08/es-modules-in-nodejs ΑΓ
Slide 95
Slide 95 text
ES Modulesͷݱঢ় • ϒϥβChromeͱFirefoxରԠࡁΈ • NodeJS֦ுࢠΛmjsͱ࣮ͯ͠ߦ͢Δ͜ͱͰରԠ • Strict mode͕ڧ੍͞ΕɺτοϓϨϕϧthisundefinedʹ • __dirnameͳͲ͑ͳ͘ͳ͍ͬͯΔͷͰҙ
Slide 96
Slide 96 text
͜͜ʹͳ͍ʁ
Slide 97
Slide 97 text
͔ͯ͠͠ʁ
Slide 98
Slide 98 text
͔ͯ͠͠ʁ CoffeeScript
Slide 99
Slide 99 text
CoffeeScript • Alt JSͷ1ͭɻRubyͳͲ͔ΒӨڹΛड͚ͨγϯλοΫεγϡΨʔ͍͔ͭ͘ ͷػೳͳػೳ͕ਓؾͩͬͨ • Ruby on Rails 3.1Ҏ߱Ͱެࣜʹαϙʔτ͞Ε͍ͯͨ • AtomϦϦʔε֤࣌छϓϥάΠϯͳͲ͕CoffeeScriptͰॻ͔Ε͍ͯͨ • JavaScriptͷੜΈͷͰ͋ΔϒϨϯμϯɾΞΠΫʮJavaScriptͷະདྷʯʹ ӨڹΛ༩͑ͨͱ໌ݴ͍ͯ͠Δ • ͪͳΈʹࠓܧଓతʹΞοϓσʔτ͞Ε͍ͯͯɺݱࡏ2ܥ͕࠷৽൛
Slide 100
Slide 100 text
CoffeeScriptͷه๏;Γ͔͑Γ Ruby෩ʹ ObjectϦςϥϧͷ{}Λলུ
Slide 101
Slide 101 text
CoffeeScriptͷه๏;Γ͔͑Γ this.ͷγϯλοΫεγϡΨʔ
Slide 102
Slide 102 text
CoffeeScriptͷه๏;Γ͔͑Γ ޙஔͷif/unless
Slide 103
Slide 103 text
arrow function
Slide 104
Slide 104 text
arrow function
Slide 105
Slide 105 text
arrow function fat arrowthisΛଋറ
Slide 106
Slide 106 text
arrow function ͜Ε͕ޙʹES2015Ͱ arrow functionΛಋೖ͢ΔͨΊͷ͖͔͚ͬʹ ͳͬͨ
Slide 107
Slide 107 text
2010 CoffeeScriptొ
Slide 108
Slide 108 text
JSͱESͷҧ͍ͷཧ • "ECMAScript" • JavaScriptݴޠͷ༷͕ऩΊΒΕ͍ͯΔ • ࣮ࡍͷϒϥβ্Ͱѻ͑ΔAPIผ్HTMLͷ༷DOMͷ༷ͱ ͯ͠ࡦఆ͞Ε͍ͯΔ • ্هશͯΛؚΊͯৗతʹ"JavaScript"ͱݺশ͍ͯ͠Δ
Slide 109
Slide 109 text
babel / browserify / Webpack ...etc ͦΕͧΕԿͷͨΊʁ
Slide 110
Slide 110 text
Babel
Slide 111
Slide 111 text
Babel • Babel (چ: 6to5) ES2015Ҏ߱ͷه๏Λ֤छϒϥβͰಈ͘ES5 Ҏલͷදݱʹม͢ΔTranspiler • ։ൃऀES2015Ҏ߱ͷه๏Ͱهड़ՄೳʹͳΓͭͭɺϢʔβʔ ʹରͯ͠ޙํޓੑΛ୲อͯ͠αʔϏεΛఏڙͰ͖Δ
Slide 112
Slide 112 text
Babel • babel-plugin • ECMAScriptͷ1ͭͷ༷ʹରԠͨ͠ม͕ϓϥάΠϯʹͳ͍ͬͯΔ • babel-preset • babel-pluginͷू߹ɻbabel-preset-2015ES2015ʹؚ·ΕΔͷ ͷू߹ɻbabel-preset-stage0, babel-preset-latest, babel-preset- envͳͲɻ
Slide 113
Slide 113 text
Babel • babel-register • NodeJSͰrequire͢ΔࡍʹઌಡΈͯ͠BabelͰcompile͢ΔΑ͏ʹ͠ ͯ͘ΕΔ • babel-polyfill • globalείʔϓͷՃ͕ඞཁͳPromiseWeakmapstatic methodͰ͋ΔArray.formͳͲΛར༻Մೳʹ͢Δ
Slide 114
Slide 114 text
Browserify
Slide 115
Slide 115 text
Browserify • CommonJSܗࣜͷmoduleͷղܾΛ͢Δπʔϧ • BrowserifyΛར༻͢Δ͜ͱͰCJS moduleΛར༻ͨ͠ϑΝΠϧ ΛϒϥβͰಡΊΔܗʹมͰ͖Δ • NodeJS͚ʹॻ͔ΕͨCJSܗࣜͷϥΠϒϥϦͳͲΛϒϥβͰ ༻Մೳʹ
Slide 116
Slide 116 text
Webpack
Slide 117
Slide 117 text
Webpack • BrowserifyͷΑ͏ͳJSͷTranspilergulpͷΑ͏ͳλεΫϥϯ φʔ͕ྲྀߦ͢ΔதɺͦΕΒΛΦʔϧΠϯϫϯతʹΈ߹Θͤͨ πʔϧͱͯ͠ొ • JSϑΝΠϧͷόϯυϦϯά͚ͩͰͳ͘ɺCSS/LESSͳͲը૾ ϑΝΠϧͳͲͷΞηοτJSϑΝΠϧͱಉ༷ʹѻ͏͜ͱ͕ग़དྷ ͨͷͰਓؾ
Slide 118
Slide 118 text
TypeScript
Slide 119
Slide 119 text
TypeScript • MicrosoftʹΑͬͯJSʹܕΛ༩͑ΔͨΊͷAltJS/Transpilerͱͯ͠ ։ൃ͞Εͨ • JavaScriptʹ੩తܕ͚ͳͲΛՃ͑ͨϓϩάϥϛϯάݴޠ • େنΞϓϦέʔγϣϯͷ։ൃʹ͑͏ΔΑ͏ʹͳ͍ͬͯΔ(?)
Slide 120
Slide 120 text
ͦͷଞͷπʔϧͨͪ • rollup • ES moduleܗࣜͷJSͷͨΊͷόϯυϦϯάπʔϧ • tree-shakingͬͯ͘ΕΔͧ • flowtype • JSʹ੩తܕ͚ͷͨΊͷه๏ΛՃ͢Δ • babelϓϥάΠϯͱͯ͠ಈ࡞͢ΔͷͰɺbabelͰॲཧ͢ΔࡍʹAST͔Βফͯ͘͠ΕΔ
Slide 121
Slide 121 text
babel / browserify / Webpack ...etc ͦΕͧΕԿͷͨΊʁ
Slide 122
Slide 122 text
ͦΕͧΕԿͷͨΊʁ • Babel • ES2015Ҏ߱ͷදݱΛඇରԠͷϒϥβͳͲͰಈ͘Α͏ʹม • Browserify • CommonJSܗࣜͷrequireΛղܾɻओʹrequireΛղܾͰ͖ͳ͍ϒϥβ͚ • Webpack • JSͷόϯυϦϯά͚ͩͰͳ͘ɺCSSը૾ͳͲऔΓѻ͏
Slide 123
Slide 123 text
·ͱΊ
Slide 124
Slide 124 text
࣍ͷ֤ߦͷίʔυ(ϒϥβ|NodeJS)Ͱಈ͘?
Slide 125
Slide 125 text
࣍ͷ֤ߦͷίʔυ(ϒϥβ|NodeJS)Ͱಈ͘? Έͳ͞Μ͑ΒΕ·͢ΑͶʁ
Slide 126
Slide 126 text
࣍ͷ֤ߦͷίʔυ(ϒϥβ|NodeJS)Ͱಈ͘? ղօ͞Μͷࣗྗݚڀʹظ͠·͢
Slide 127
Slide 127 text
·ͱΊ • "JavaScript"ͷ༷ECMAScript͚ͩͰͳ͘WHATWG HTML Living StandardͳͲؚΜͰ͍Δ • ͜͜ʹࢸΔ·Ͱʹ৭ʑͳܦҢ͕͋ͬͨ • JavaScriptͷݱࡏͷπʔϧͨͪ͜Ε·Ͱͷྺ࢙ͷෛ࠴ͱະདྷͷࢿͷͨ ΊͷؒΛܨ͍Ͱ͘Ε͍ͯΔ • ίϯςΩετΛཧղͯ͠దࡐదॴͰֶΜͩΓ͍ͬͯ͜͏
Slide 128
Slide 128 text
ࢀߟจݙ • [ThinkIT] ୈ2ճɿGoogleWebͷৗࣝΛృΓସ͑ͨ (1/4) https://thinkit.co.jp/free/article/0612/22/2/ • GoogleΤϯδχΞɿʮGoogle Mapsͷެ։ͰAJAXͷؔ৺͕ߴ·ͬͨʯ - ZDNet Japan https://japan.zdnet.com/article/20085943/ • ECMAScript 4 ͷ Draft Λͬ͘͟ΓಡΜͰΈͨ - ͯͬࣽ͘ϒϩά http://tech.nitoyon.com/ja/blog/2007/10/30/es4-overview/ • JavaScript - Wikipedia https://ja.wikipedia.org/wiki/JavaScript • ECMAScript 4ͷඪ४Խ͕தࢭ͞ΕΔ | εϥυ σϕϩούʔ https://developers.srad.jp/story/08/08/19/0714251/ • JavaScript 1.7 ͷ৽ػೳ: Days on the Moon http://nanto.asablo.jp/blog/2006/08/12/481381#js17-block-scope • JavaScript ୈ6൛, David Flanagan ஶɺଜ্ ྻ ༁, ΦϥΠϦʔδϟύϯ • JavaScript 2.0ECMAScript 3.1ϕʔεʹɺECMAScript 4ৡา | ϚΠφϏχϡʔε https://news.mynavi.jp/article/20080818-a027/ • ECMAScript 5ϦϦʔε https://www.infoq.com/jp/news/2009/12/ecmascript5 • ECMAScript6ͷ৽ػೳ - Qiita https://qiita.com/rana_kualu/items/1f98c1a642102f48aa78 • ECMAScriptͷ͍ํ http://azu.github.io/slide/2018/node/ecmascript39.html • ES6ͷ৽ػೳʮclassߏจʯ – جૅฤ – | ES6ͷ͋Δʹੜ·Εͯ https://liginc.co.jp/266587 • Node.jsͷES Modulesαϙʔτͷݱঢ়֬ೝͱඋ͑ - teppeis blog https://teppeis.hatenablog.com/entry/2017/08/es-modules-in-nodejs • Strict Ϟʔυ - JavaScript | MDN https://developer.mozilla.org/ja/docs/Web/JavaScript/Strict_mode • WHATWG൛ͱW3C൛͕͋Δ༷ͨͪ - Unreviewed http://takenspc.hatenablog.com/entry/2015/12/03/235927 • ͓ͬ͞ΜES6/ES2015,React.jsΛֶͿ https://www.slideshare.net/dcubeio/es6es2015reactjs