Upgrade to Pro — share decks privately, control downloads, hide ads and more …

フロントエンドの基礎知識

Go Tanaka
February 17, 2017

 フロントエンドの基礎知識

Go Tanaka

February 17, 2017
Tweet

More Decks by Go Tanaka

Other Decks in Technology

Transcript

  1. )5.-ຄڵظ ೥ࠒʙʣ ɾ8)"58(ͱ8$ ɹɾ8$ͷ9)5.-ͷํ޲ੑ΁ͷٙ໰ ɹɾ8FC"QQMJDBUJPOTˠ)5.- ɹɾϒϥ΢β্ͰΞϓϦΛ࡞Δ౔୆͕Ͱ͖ͨ ɹɹɾ$BOWBT 8FC4UPSBHF WJEFP ɹɹɾϨεϙϯγϒσβΠϯʢ$44ʣ

    8$ʜ)5.-ͷ࢓༷ܾΊͯΔஂମ 8)"58(ʜ8FC)ZQFSUFYU"QQMJDBUJPO5FDIOPMPHZ8PSLJOH(SPVQ ɹɹɹɹɹɹ"QQMF .P[JMMB 0QFSBʹΑͬͯઃཱ͞Εͨ 8JLJQFEJB
  2. +4൙ཞظ ೥ࠒʙʣ ɾJ1IPOFͷొ৔ ɾ'MBTI͕ͳ͘ͳͬͨ &4׬શʹ಴࠳  ɾϞόΠϧϑΝʔετ ɾΞϓϦ։ൃ͸J04"OESPJE ɾλϒϨοτΞϓϦΛ8FCϒϥ΢βͰಈ͔͢ ɾ+4Ͱ41"ͷधཁ͕ٸ଎తʹ૿͑ͨ

    41"ʜγϯάϧϖʔδΞϓϦέʔγϣϯ &4ʜ&$."4DSJQUɻ&$."4DSJQU͸+BWB4DSJQUͷඪ४Ͱ͋Γ &DNB*OUFSOBUJPOBMͷ΋ͱͰඪ४Խखଓ͖ͳͲ͕ߦΘΕ͍ͯΔ &4ˠ&4ʢ಴࠳ʣˠ&4ˠ&4&4ͷ࢓༷ܾఆʹ೥͔͔Δ
  3. &4Ҏ߱ͷࡦఆϓϩηε &$."4DSJQU͔Β͸ػೳ͝ͱʹ࢓༷ͷϓϩϙʔβϧ ఏҊ Λग़͠ ࡦఆ͍ͯ͘͜͠ͱʹͳͬͨɻͦΕͧΕͷϓϩϙʔβϧʹ͸4UBHFͱݺ͹ ΕΔஈ֊ͷϥϕϧ͕ৼΒΕ͍ͯΔɻ4UBHFͱͳͬͨϓϩϙʔβϧ͸࣍ ظ&$."4DSJQUʹऔΓࠐ·Εɺਖ਼ࣜʹ&$."4DSJQUͷ࢓༷ͱͳΔɻ 4USBXNBOʜΞΠσΞ  1SPQPTBMʜఏҊɻ໨త΍ղܾํ๏Λࣔ͢

    %SBGUʜυϥϑτɻ&$."4DSJQUඪ४ͱಉ͡ߏจ΍ηϚϯςΟΫεͰهड़ $BOEJEBUFʜ࢓༷͸׬੒ͨ͠ঢ়ଶɻ࣮૷΍֎෦ͷϑΟʔυόοΫΛٻΊΔঢ়ଶ 'JOJTIFEʜ&$."4DSJQU΁औΓࠐ·ΕΔ४උ͕׬ྃͨ͜͠ͱΛࣔ͢ঢ়ଶ
  4. Ξϩʔؔ਺ var a = [ "Hydrogen", "Helium", "Lithium", "BerylÂlium" ];

    // ES5 var a2 = a.map(function(s){ return s.length }); // ES2015 var a3 = a.map( s => s.length );
  5. function Person() { var self = this; self.age = 0;

    setInterval(function growUp() { self.age++; }, 1000); } ޠኮతͳUIJT &4 function Person(){ this.age = 0; setInterval(() => { this.age++; }, 1000); } &4ʢΞϩʔؔ਺͕είʔϓ಺ͷUIJTͷ஋Λัଊ͢Δʣ
  6. Ϋϥε class Animal { constructor(name) { this.name = name; }

    speak() { console.log(this.name + ' makes a noise.'); } } class Dog extends Animal { speak() { console.log(this.name + ' barks.'); } } var dog = new Dog(‘Wanko'); dog.speak(); // Wanko barks. +BWB4DSJQUʹ͢Ͱʹ͋ΔϓϩτλΠϓϕʔεܧঝͷ౶ҥߏจɻΫϥεߏ จ͸ɺ৽͍͠ΦϒδΣΫτࢦ޲ܧঝϞσϧΛ+BWB4DSJQUʹಋೖ͍ͯ͠ ΔΘ͚Ͱ͸ͳ͍ͷͰ஫ҙ͕ඞཁɻʢ˞Ϋϥε͸ʮಛผͳؔ਺ʯѻ͍ʣ
  7. ఆ਺ʢDPOTUʣͱہॴม਺ʢMFUʣ function test() { const x = 31; if (true)

    { const x = 71; console.log(x); // 71 } console.log(x); // 31 x = 32; // Error } ఆ਺ͷ஋͸ɺ࠶୅ೖʹΑΔมߋ͸Ͱ͖ͣɺ࠶એݴ΋Ͱ͖ͳ͍ɻ MFUʢޙड़ʣͱಉ͘͡ϒϩοΫείʔϓɻ ఆ਺
  8. ఆ਺ʢDPOTUʣͱہॴม਺ʢMFUʣ function test() { let x = 31; if (true)

    { let x = 71; console.log(x); // 71 } console.log(x); // 31 x = 32; console.log(x); // 32 } MFUจ͸ϒϩοΫείʔϓͷہॴม਺ΛએݴͰ͖Δɻ ೚ҙͰ஋Λ୅ೖͯ͠ॳظԽͰ͖Δɻ ہॴม਺
  9. .BQ4FU var map = new Map([ ['one', '111'] ]); map.set('two',

    'aaa'); map.set('two', 'bbb'); console.log(map.get('one')); // 111 console.log(map.get('two')); // bbb console.log(map.size); // 2 console.log(map.has('one')); // true var set = new Set([1, 'one', function (){}]); set.add(2); set.add(1); // Կ΋͓͜Βͳ͍ console.log(set.has('one')); // true console.log(set.size); // 4 set.delete(1); console.log(set.size); // 3
  10. ςϯϓϨʔτจࣈྻ var name = 'John'; var country = 'Japan'; console.log(`Hello!

    My name is ${name}. I live in ${country}.`); // Hello! My name is John. I live in Japan. var today = new Date(); console.log(`Today is ${today.getFullYear()}/${today.getMonth()+1}/${today.getDate()}`); // Today is 2017/2/18
  11. σϑΥϧτҾ਺Մม௕Ҿ਺ function multiply(a, b = 1) { return a*b; }

    multiply(5); // 5 function f(x, ...y) { // y is an Array return x * y.length; } f(3, "hello", true) == 6
  12. openFile('foo.txt', (event, xhr) => { openFile('bar.txt', (event, xhr) => {

    openFile('baz.txt', (event, xhr) => { console.log('done!'); }); }); }); ίʔϧόοΫ஍ࠈ ΑΓهड़͠΍͍͢௨৴ॲཧ &4
  13. Promise var request = require('superagent') function fetch(path) { return new

    Promise( (resolve, reject) => { request.get("https://api.github.com" + path) .end((err, res) => { if (err) { reject(err); } else { resolve(JSON.parse(res.text)); } }); }); } fetch("/users/tango238") .then((obj) => { console.log(obj); return fetch("/users/tango238/repos"); }) .then((obj) => console.log(obj)) .catch(function(err) { console.error(err); }); Promise Λฦ͢ ΑΓهड़͠΍͍͢௨৴ॲཧ &4
  14. var request = require('superagent') function fetch(path) { return new Promise(

    (resolve, reject) => { request.get("https://api.github.com" + path) .end((err, res) => { if (err) { reject(err); } else { resolve(JSON.parse(res.text)); } }); }); } async function getRepos() { await fetch("/users/tango238") .then((obj) => console.log(obj)) .catch((err) => console.error(err)); await fetch("/users/tango238/repos") .then((obj) => console.log(obj)) .catch((err) => console.error(err)); } ΑΓهड़͠΍͍͢௨৴ॲཧ &4 async / await await ͸ async ͕͍ͭͨؔ਺ͷதͰ͔͠࢖͑ͳ͍
  15. OQN /PEFKTͰ࢖͏ύοέʔδϚωʔδϟɻඪ४ͩͱࢥ͑͹͍͍ɻ #PXFS +BWB4DSJQU $44 )5.-ͳͲΛґଘؔ܎ΛؚΊͯ؅ཧͯ͘͠ΕΔɺϑϩϯτΤϯυ༻ ύοέʔδϚωʔδϟɻOQNͱ#SPXTFSJGZ ޙड़ ͕͋Ε͹ඞཁͳ͍ͷͰඍົͳཱͪ Ґஔɻ

    ࠷ۙݟ͔͚ͳ͍ɻ5XJUUFS੡ɻ ZBSO QBDLBHFKTPO͕ͦͷ··࢖͑ΔɻZBSOMPDL͕ੜ੒͞ΕΔɻ͜Ε͸OQNͷ TISJOLXSBQʹ૬౰͢ΔػೳͰύοέʔδͷόʔδϣϯ͕ݻఆͰ͖Δɻ ϞδϡʔϧͷΠϯετʔϧ͕଎͍ɻ'BDFCPPL੡ɻ w ύοέʔδϚωʔδϟ
  16. CommonJS / Browserify / AMD / RequireJS / webpack $PNNPO+4

    $PNNPO+4ͱ͍͏ϓϩδΣΫτɻ+4Ͱ։ൃ͢ΔͨΊͷඪ४తͳ"1*ͷ࢓༷ΛఆΊ Δɻ .PEVMFͱ1SPNJTFʹ͍ͭͯ͸ɺ&4Ͱඪ४ن͕֨ఆΊΒΕ͍ͯΔɻ #SPXTFSJGZ $PNNPO+4ͷϞδϡʔϧ࢓༷ʹԊͬͯॻ͍ͨ+BWB4DSJQUΛϒϥ΢β্Ͱಈ͔ͤΔ Α͏ʹͨ͠ϞδϡʔϧγεςϜɻ Ϟδϡʔϧ
  17. CommonJS / Browserify / AMD / RequireJS / webpack ".%

    "TZODISPOPVT.PEVMF%FpOJUJPOͷུɻϞδϡʔϧΛඇಉظͰϩʔυ͢Δ࢓૊Έ ΍ఆٛͱ͍ͬͨ"1*ͷ࢓༷Λࢦ͢ɻ 3FRVJSF+4 ".%Λϒϥ΢β্Ͱಈ͔ͤΔΑ͏ʹͨ͠ϞδϡʔϧγεςϜɻ XFCQBDL ޙൃͷϞδϡʔϧόϯυϥʔɻ$PNNPO+4ɺ".%ɺ&4ͷܗ͕ࣜ࢖͑Δɻ Ϟδϡʔϧ