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

今から始めるES2015

 今から始めるES2015

社内勉強会にて発表した今からES2015を始める人のための資料です。

Sota Sugiura

June 16, 2016
Tweet

More Decks by Sota Sugiura

Other Decks in Programming

Transcript

  1. UIJT໰୊ var cat = { name: 'tama', say: function ()

    { console.log(this.name); // ‘tama’ function say() { console.log(this.name); // ?? } say(); } }; cat.say();
  2. UIJT໰୊ var cat = { name: 'tama', say: function ()

    { console.log(this.name); // ‘tama’ function say() { console.log(this.name); // undefined } say(); } }; cat.say();   
  3. ίʔϧόοΫ஍ࠈ asyncOne('hoge', function (res, err) { asyncTwo(res, function (res, err)

    { asyncThree(res, function (res, err) { asyncFour(res, function (res, err) { asyncFive(res, function (res, err) { console.log(res); // ඇಉظϚγϚγ }); }); }); }); });
  4. ҉໧ͷάϩʔόϧม਺ var show = function () { var name =

    'sota1235'; var age = (function (now) { birthday = 1992; return now - birthday; })(2016); console.log(name + ' is ' + age + ' years old.'); }; show(); // ‘sota1235 is 24 years old.’ /** after 100000 lines... */ console.log(name); // undefined console.log(age); // undefined console.log(birthday); // ??
  5. ҉໧ͷάϩʔόϧม਺ var show = function () { var name =

    'sota1235'; var age = (function (now) { birthday = 1992; return now - birthday; })(2016); console.log(name + ' is ' + age + ' years old.'); }; show(); // ‘sota1235 is 24 years old.’ /** after 100000 lines... */ console.log(name); // undefined console.log(age); // undefined console.log(birthday); // 1992   
  6. MFU for (let i = 0; i < 5; i++)

    { console.log(i); } console.log(i); // ReferenceError let name = 'sota1235'; // ࠶୅ೖՄ name = 'sota1236'; // ࠶એݴෆՄ let name = 'sota1236'; // TypeError
  7. BSSPXGVODUJPO // ES5 var func = function (food, name) {

    console.log(name + ' want to eat ' + food); }; // ES2015 const func = (food, name) => { console.log(name + ' want to eat ' + food); }; // Ҿ਺͕1ͭͷ৔߹ɺؙׅހলུՄೳ const func2 = food => { console.log('I want to eat ' + food); }; // ॲཧ͕ҰߦͳΒதׅހলུՄೳ // ධՁ͞Εͨ஋͕҉໧ͷreturn஋ͱͳΔ఺ʹ஫ҙ const func3 = food => console.log('I want to eat ' + food);
  8. EFGBVMUQBSBNFUFSWBMVFT // lastͷσϑΥϧτ஋Λࢦఆ const getName = (first, last = 'Sugiura')

    => { return last + ' ' + first; }; // ม਺ʹೖΔ΋ͷ͸ԿͰ΋ࢦఆՄೳ const concat = (list, subList = ['c']) => { return list.concat(subList); }; concat(['a', 'b']); // ['a', 'b', 'c'] concat(['a', 'b'], ['d']); // ['a', 'b', 'd']
  9. TQSFBEPQFSBUPS // ഑ྻΛల։ const a = ['a', 'b', 'c']; const

    b = [...a, 'd']; // ['a', 'b', 'c', 'd']; // Մม௕Ҿ਺ function print(...names) { console.log(names.join(' ')); }; print('es5', 'es6', 'es7'); // 'es5 es6 es7'
  10. QBSBNFUFSDPOUFYUNBUDIJOH const meal = { breakfast : 'bread', lunch :

    'pasta', dinner : 'curry', }; const { breakfast, lunch } = meal; console.log(breakfast); // 'bread' console.log(lunch); // 'pasta' function printLunch({ lunch }) { console.log('Lunch is ' + lunch); }; printLunch(meal); // 'Lunch is pasta'
  11. DMBTT class Dog { constructor(name, age) { this.name = name;

    this.age = age; } printName() { console.log(this.name); } static bark() { console.log('Wow'); } get age() { return this.age; } } Dog.bark(); // 'Wow' const dog = new Dog('chiwawa', 18); dog.printName(); // 'chiwawa'; console.log(dog.age); // 18
  12. WBMVFFYQPSUJNQPSU // module.js export default function cat() { console.log('myaw'); }

    export config = { env: 'develop', }; // sample.js import cat, { config } from './module'; cat(); // 'myaw' console.log(config.env); // 'develop';
  13. 1SPNJTF // Not good :( asyncFirst('hoge', result => { asyncSecond(result,

    result => { asyncThird(result, result => { console.log(result); }); }); }); // Good promise :) asyncFirst('hoge') .then(asyncSecond) .then(asyncThird) .then(result => console.log(result)); .catch(err => console.error(err));
  14. ϒϥ΢βରԠঢ়گ w *&͸࿦֎ w &EHF ''͸࠷৽൛ͳΒ w $ISPNF 0QFSB͸࠷৽൛ͳΒ w

    εϚϗ͸࠷େͱ݁ߏյ໓త ࣌఺IUUQTLBOHBYHJUIVCJPDPNQBUUBCMFFT
  15. ͪͳΈʹ w ҎԼͷ΋ͷ͸#BCFM͸ඞཁͳ͍Ͱ͢ w OPEFKTWd w Ϟμϯϒϥ΢β $ISPNF '' &EHF͋ͨΓ

     w ΧόʔͰ͸ͳ͍͚Ͳ͍͍ͩͨಈ͘ͷͰ࿅ श࣌͸ͪ͜Βͷํ͕Φεεϝ