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

いまからはじめるECMAScript 6 / Begin ECMAScript6

いまからはじめるECMAScript 6 / Begin ECMAScript6

2015年6月13日に行われたHTML5オールスターズ勉強会の「いまからはじめるECMAScript 6」のセッションの資料です。

Shogo Sensui

June 13, 2015
Tweet

More Decks by Shogo Sensui

Other Decks in Technology

Transcript

  1. let const { var foo = 10; let bar =

    100; const baz = 1000; console.log(foo, bar, baz); // => 10, 100, 1000 } console.log(foo, bar, baz); // => 10, undefined, undefined ES6
  2. Arrow Functions $('button').on('click', function (e) { console.log(this); // => button

    }); $('button').on('click', (e) => { console.log(this); // => window }); $('button').on('click', e => console.log(this)); ES5 ES6 ES6
  3. import export // export.js export function foo() { console.log('foo'); }

    export function bar() { console.log('bar'); } // import.js import { foo, bar } from './export.js'; foo(); // => foo bar(); // => bar ES6
  4. Rest Parameters let x = 10, y = 20, z

    = 30; function max(array) { return Math.max.apply(null, array); } max([x, y, z]); // => 30 function max(...array) { return Math.max.apply(null, array); } max(x, y, z); // => 30 ES6 ES6
  5. Default Parameters function add(arg1, arg2) { if (arg1 === undefined)

    { arg1 = 0; } if (arg2 === undefined) { arg2 = 0; } return arg1 + arg2; } function add(arg1 = 0, arg2 = 0) { return arg1 + arg2; } ES5 ES6
  6. let hundred = 100; let multiple = function (x, y)

    { return x * y; } console.log(`hundred is ${number}`); // => hundred is 100 console.log(`hundred * 10 is ${multiple(number, 10)}`); // => hundred * 10 is 1000 Template Strings ES6
  7. function Human (message) { this.message = message; } Human.prototype.hello =

    function () { console.log(this.message); } class Human { constructor(message) { this.message = message; } hello() { console.log(this.message); } } Class ES6 ES5
  8. function* toThree() { yield 1; yield 2; return 3; }

    console.log(toThree()); // => 1 console.log(toThree()); // => 2 console.log(toThree()); // => 3 Generator Functions ES6
  9. Proxy var person = { firstName: 'Taro', lastName: 'Tanaka' };

    var interceptor = { set: function (target, name, value, receiver) { console.log(name + ' is changed.'); target[name] = value; } get: function (target, name, receiver) { return name + ' is ' target[name]; } }; person = new Proxy(person, interceptor); ES6
  10. Symbol var sym1 = Symbol(); var sym2 = Symbol("foo"); var

    sym3 = Symbol("foo"); Symbol("foo") === Symbol("foo"); // => false ES6
  11. Promise new Promise(function (resolve, reject) { resolve(10); }).then(function (value) {

    return value * 10; }).then(function (value) { console.log(value); // 100 }); ES6
  12. Set WeakSet var set1 = new Set([1, 2, 2, 3,

    3, 3, 4, 4, 4, 4]); // => [1, 2, 3, 4] var set2 = new Set(set1); var set3 = new Set(set1.entries()); var set4 = new Set(set1.keys()); ES6
  13. Map WeakMap var arrayKey = []; var map = new

    Map(); map.set(1, 'This is a value'); map.set(arrayKey, 'This is also value'); map.get(1); // This is a value map.get(arrayKey); // This is also value ES6