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

ビギナーズ_レビューから学ぶ+1

 ビギナーズ_レビューから学ぶ+1

第13回HTML5ビギナーズ。ソースレビューを半年以上していて、その内容をまとめました。「バグがなくて読みやすい」がポイント。

Yohei Munesada

November 05, 2015
Tweet

More Decks by Yohei Munesada

Other Decks in Technology

Transcript

  1. About me 㾎 फఆ༸ฏ 㾎 גࣜձࣾϒοΫςʔϒϧ 㾎 !ZPIFJ.VOF 㾎 IUUQXXXZPIFJNOFU

    㾎 )5.-ϏΪφʔζελοϑ 㾎 δʔεΞΧσϛʔϝϯλʔ 㾎 ࠷ۙͷڵຯɿ1ZUIPO ػցֶश ਺ֶ ౷ܭ
  2. όά͕ͳ͍ ᶃ࢓༷௨Γʹಈ͘ w ࢓༷ͷ௨Γʹಈ͘ w ແବͳ͜ͱ͸͠ͳ͍   w ͋Γ͑ΔΤϥʔέʔεʹରԠ͍ͯ͠Δ

     ᶄ Ћ কདྷతʹ΋όάʹͳΓͮΒ͍ w ࠓޙ͋Γͦ͏ͳมߋʹ଱͑͏ΔઃܭͰ͋Δ   w ࠓ͸࣮૷͢Δඞཁ͸ͳ͍͚Ͳ
  3. ࢓༷௨Γʹಈ͘ model.book.fetchOne = function (bookName, callback) { var url =

    '/api/book/search'; var params = {name: bookName}; api(url, params).then(function (books) { callback(books[0]); }); }
  4.  ແବͳ͜ͱ͸͠ͳ͍όά͕ͳ͍ // OK model.book.fetchOne = function (bookName, callback) {

    var url = '/api/book/search'; var params = {name: bookName}; api(url, params).then(function (books) { callback(books[0]); }); }
  5.  ແବͳ͜ͱ͸͠ͳ͍όά͕ͳ͍ // NG model.book.fetchOne = function (bookName, callback) {

    var url = '/api/book/search'; var params = {name: bookName}; api(url, params).then(function (books) { $(‘.mypage #btn’).addClass('enable'); ແବͳ͜ͱ callback(books[0]); }); }
  6.  ΤϥʔέʔεʹରԠ͍ͯ͠Δόά͕ͳ͍ model.book.fetchOne = function (bookName, callback) { var url

    = '/api/book/search'; var params = {name: bookName}; api(url, params).then(function (books) { callback(books[0]); }); }
  7.  ΤϥʔέʔεʹରԠ͍ͯ͠Δόά͕ͳ͍ model.book.fetchOne = function (bookName, callback) { var url

    = ‘/api/book/search'; // 1. bookName͕ະࢦఆʁ var params = {name: bookName}; api(url, params).then(function (books) { // 2. ݕࡧ݁Ռͳ͠ʢnull͕ฦͬͯ͘Δʣʁ // 3. callback͕ະࢦఆʁ callback(books[0]); }); }
  8.  ΤϥʔέʔεʹରԠ͍ͯ͠Δόά͕ͳ͍ model.book.fetchOne = function (bookName, callback) { var url

    = ‘/api/book/search'; // 1. bookName͕ະࢦఆʁ => ࠓճ͸ؾʹ͠ͳ͍ var params = {name: bookName}; api(url, params).then(function (books) { // 2. ݕࡧ݁Ռͳ͠ʢۭͷ഑ྻ͕ฦͬͯ͘Δʣ=> nullνΣοΫ // 3. callback͕ະࢦఆʁ => ؾʹ͠ͳ͍ callback(books && books[0]); }); }
  9.  ࠓޙͷมߋʹڧ͍όά͕ͳ͍ model.book.fetchOne = function (bookName, callback) { var url

    = '/api/book/search'; var params = {name: bookName}; api(url, params).then(function (books) { callback(books[0]); }); }
  10.  ࠓޙͷมߋʹڧ͍όά͕ͳ͍ // ύϥϝʔλ͕૿͑Δʁ model.book.fetchOne = function (bookName, callback) {

    var url = '/api/book/search'; var params = {name: bookName}; api(url, params).then(function (books) { callback(books[0]); }); }
  11.  ࠓޙͷมߋʹڧ͍όά͕ͳ͍ // ύϥϝʔλ͕૿͑Δʁ => Ҿ਺Λ௥Ճ͢Δ model.book.fetchOne = function (name,

    callback, genre, author) { var url = '/api/book/search'; var params = {name: bookName}; api(url, params).then(function (books) { callback(books[0]); }); }
  12.  ࠓޙͷมߋʹڧ͍όά͕ͳ͍ // ύϥϝʔλ͕૿͑Δʁ model.book.fetchOne = function (name, callback, genre,

    author) { var url = '/api/book/search'; var params = {name: bookName}; api(url, params).then(function (books) { callback(books[0]); }); }
  13.  ࠓޙͷมߋʹڧ͍όά͕ͳ͍ // ύϥϝʔλ͕૿͑Δʁ => ෳ਺ࢦఆՄೳʹ model.book.fetchOne = function (conditions,

    callback) { var url = '/api/book/search'; api(url, conditions).then(function (books) { callback(books[0]); }); } // ࢖͍ํ model.book.fetchOne({name:’φϧτ’}, callback: function () {});
  14. 3Fɿόά͕ͳ͍ ᶃ࢓༷௨Γʹಈ͘ w ࢓༷ͷ௨Γʹಈ͘ w ແବͳ͜ͱ͸͠ͳ͍   w ͋Γ͑ΔΤϥʔέʔεʹରԠ͍ͯ͠Δ

     ᶄ Ћ কདྷతʹ΋όάʹͳΓͮΒ͍ w ࠓޙ͋Γͦ͏ͳมߋʹ଱͑͏ΔઃܭͰ͋Δ   w ࠓ͸࣮૷͢Δඞཁ͸ͳ͍͚Ͳ
  15. ಡΈ΍͍͢ιʔείʔυΛॻ͘ʹ͸ʁ 㾎 ॲཧΛ෼ׂ͢Δ 㾎 Θ͔Γ΍͍͢ม਺໊Λ͚ͭΔ 㾎 ద੾ͳίϝϯτΛ͚ͭΔ 㾎 ΠϯσϯτΛద੾ʹͱΔ 㾎

    ൱ఆΑΓ΋ߠఆΛ࢖͏ 㾎 ωετΛઙ͘͢Δ 㾎 ؆ܿʹॻ͘ 㾎 HPUPจΛ࢖Θͳ͍ 㾎 είʔϓͷൣғ͸࠷খݶʹ͢Δ 㾎 ୯Ұ੹೚ͷݪଇ 㾎 ίʔυΛখ͘͞อͭ 㾎 ࣮૷ͷҙਤΛ࢒͢ 㾎 ໊લ෇͖Ҿ਺ 㾎 Ҿ਺ͷ਺͸ͭ·Ͱ 㾎 ૬ޓࢀরΛආ͚Δ 㾎 ίʔϧόοΫ஍ࠈΛආ͚Δ 㾎 ΦϒδΣΫτͷґଘ౓ΛԼ͛Δ 㾎 ͳͲ
  16. ಡΈ΍͍͢ιʔείʔυΛॻ͘ʹ͸ʁ 㾎 ॲཧΛ෼ׂ͢Δ 㾎 Θ͔Γ΍͍͢ม਺໊Λ͚ͭΔ 㾎 ద੾ͳίϝϯτΛ͚ͭΔ 㾎 ΠϯσϯτΛద੾ʹͱΔ 㾎

    ൱ఆΑΓ΋ߠఆΛ࢖͏ 㾎 ωετΛઙ͘͢Δ 㾎 ؆ܿʹॻ͘ 㾎 HPUPจΛ࢖Θͳ͍ 㾎 είʔϓͷൣғ͸࠷খݶʹ͢Δ 㾎 ୯Ұ੹೚ͷݪଇ 㾎 ίʔυΛখ͘͞อͭ 㾎 ࣮૷ͷҙਤΛ࢒͢ 㾎 ໊લ෇͖Ҿ਺ 㾎 Ҿ਺ͷ਺͸ͭ·Ͱ 㾎 ૬ޓࢀরΛආ͚Δ 㾎 ίʔϧόοΫ஍ࠈΛආ͚Δ 㾎 ΦϒδΣΫτͷґଘ౓ΛԼ͛Δ 㾎 ͳͲ
  17. ෼͔Γ΍͍͢ม਺໊Λ͚ͭΔ // Is it an array? -> isArray -> Yes

    / No (True / False) function isArray (arrayObject) {} // Does this array contain the item ? => Yes / No (True / False) function contains(array, item) {} // ಈࢺ + ໨తޠ function fetchBooks () {} // ಈࢺΛબͿ => ӳޠྗ + ஌͕ࣝඞཁ function push() / append() / put() / add() / enqueue() / etc // ಈࢺ͡Όͳͯ͘΋໌֬ͳ৔߹΋ function api () {}
  18. ಡΈ΍͍͢ιʔείʔυΛॻ͘ʹ͸ʁ 㾎 ॲཧΛ෼ׂ͢Δ 㾎 Θ͔Γ΍͍͢ม਺໊Λ͚ͭΔ 㾎 ద੾ͳίϝϯτΛ͚ͭΔ 㾎 ΠϯσϯτΛద੾ʹͱΔ 㾎

    ൱ఆΑΓ΋ߠఆΛ࢖͏ 㾎 ωετΛઙ͘͢Δ 㾎 ؆ܿʹॻ͘ 㾎 HPUPจΛ࢖Θͳ͍ 㾎 είʔϓͷൣғ͸࠷খݶʹ͢Δ 㾎 ୯Ұ੹೚ͷݪଇ 㾎 ίʔυΛখ͘͞อͭ 㾎 ࣮૷ͷҙਤΛ࢒͢ 㾎 ໊લ෇͖Ҿ਺ 㾎 Ҿ਺ͷ਺͸ͭ·Ͱ 㾎 ૬ޓࢀরΛආ͚Δ 㾎 ίʔϧόοΫ஍ࠈΛආ͚Δ 㾎 ΦϒδΣΫτͷґଘ౓ΛԼ͛Δ 㾎 ͳͲ
  19. ·ͱΊ ᶃόά͕ͳ͍ w ࢓༷௨Γʹಈ͖ɺΤϥʔέʔε΁ͷߟྀ΋͋Δ w কདྷతʹ΋όάʹͳΓͮΒ͍ ᶄಡΈ΍͍͢ w ೔ຊޠͷจষͱҰॹ w

    ͨ͘͞Μͷϊ΢ϋ΢͕ଘࡏ͢Δʢม਺໊ͷ෇͚ํͳͲʣ ᶅνʔϜͷ੒௕Λଅ͢ w ΈΜͳͰϨϏϡʔ͢Δ