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

Vanilla JSの今

Gen Tamura
February 06, 2020

Vanilla JSの今

Meguro.es # 25 @ Fringe81

Gen Tamura

February 06, 2020
Tweet

Other Decks in Programming

Transcript

  1. ͨΉΒ͛Μ / ాଜݩ Twitter @gentamura84 / GitHub @gentamura ʙ2019೥12݄ גࣜձࣾπΫϧό

    ϑϩϯτΤϯυΤϯδχΞ 2020೥1݄ʙ ϑϦʔϥϯεΤϯδχΞ ECMAScript วྺ ͜Ε·Ͱ ActionScript3 / Knockout.js / Backbone.js / jQuery ࠷ۙ React / Next.js / TypeScript Firebase / GatsbyJS / NetlifyCMS
  2. ES2015 - class - import / export - Arrow function,

    Default parameters, Rest parameters - let / const - for .. of - Generator - Promise, Map, Set, Proxy ͳͲͳͲɺͨ͘͞Μ͋Γ·ͨ͠ http://kangax.github.io/compat-table/es6/
  3. ES2015 - class (class એݴ) class Polygon { constructor(height, width)

    { this.area = height * width; } } console.log(new Polygon(4,3).area); index.js https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/class
  4. ES2015 - class (class ࣜ) const Rectangle = class {

    constructor(height, width) { this.height = height; this.width = width; } area() { return this.height * this.width; } } console.log(new Rectangle(5,8).area()); // expected output: 40 index.js https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/class
  5. ES2015 - import / export module https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/import https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Statements/export <script src="./index.js"type="module"></script>

    <!— ·ͨ͸ —> <script type="module"> import hello from ‘./hello.js'; hello(); </script> index.html import hello from './hello.js'; hello(); index.js const hello = () => { console.log('hello world'); }; export default hello; hello.js
  6. ES2015 - Generator function* generator(i) { yield i; yield i

    + 10; } const gen = generator(10); console.log(gen.next()); // expected output: Object { value: 10, done: false } console.log(gen.next()); // expected output: Object { value: 20, done: false } console.log(gen.next()); // expected output: Object { value: undefined, done: true } index.js https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Generator
  7. ES2016 - Array.prototype.includes() const pets = ['cat', 'dog', 'bat']; console.log(pets.includes(‘cat'));

    console.log(pets.indexOf(‘cat') > -1); // old style // expected output: true console.log(pets.includes(‘at')); console.log(pets.indexOf(‘at') > -1); // old style // expected output: false index.js https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Global_Objects/Array/ includes
  8. ES2016 - ΂͖৐ԋࢉࢠ (**) 2 ** 3 // 8 3

    ** 2 // 9 3 ** 2.5 // 15.588457268119896 10 ** -1 // 0.1 NaN ** 2 // NaN 2 ** 3 ** 2 // 512 2 ** (3 ** 2) // 512 (2 ** 3) ** 2 // 64 ※ LaTeX΍Excel͸ ^ ͕΂͖৐ʹͳΓ·͕͢ɺJavaScriptͰ͸ϏοτԋࢉࢠʹͳΔͷͰ஫ҙ index.js https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/ Arithmetic_Operators
  9. ES2017 async function => PromiseͷγϯλοΫεγϡΨʔ ؔ਺ͷ຤ඌͷΧϯϚ => Λڐ༰ Object static

    methods Object.values() => ஋ͷ഑ྻΛฦ͢ Object.entries() => [key, value] Ͱ֨ೲͨ͠഑ྻΛฦ͢ Object.getOwnPropertyDescriptors() => objectͷDescriptorΛฦ͢ Shared memory and atomics http://kangax.github.io/compat-table/es2016plus/ https://www.ecma-international.org/ecma-262/8.0/index.html
  10. ES2018 Rest/Spread Properties => Object Ϧςϥϧ (ؔ਺Ҿ਺, Array͸ES2015) Promise.prototype.finally() =>

    Resolve, RejectʹؔΘΒ࣮ͣߦ Asynchronous iteration => ඇಉظgeneratorΛϧʔϓͤ͞Δ http://kangax.github.io/compat-table/es2016plus/ https://www.ecma-international.org/ecma-262/9.0/index.html
  11. ES2018 - Asynchronous iteration async function getData () { updateStatus('0/2')

    const data1 = await (await fetch(url1)).json() updateStatus('1/2') const data2 = await (await fetch(url2)).json() updateStatus('2/2') return {data1, data2} } Before https://qiita.com/cognitom/items/e67c7df29a238decf49f async function* getData () { yield {status: '0/2'} const data1 = await (await fetch(url1)).json() yield {status: '1/2', data1} const data2 = await (await fetch(url2)).json() yield {status: '2/2', data2} } After
  12. ES2020 String.prototype.matchAll() Promise.allSettled() BigInt globalThis for-in mechanics Optional chaining Nullish

    coalescing operator ͳͲͳͲ http://kangax.github.io/compat-table/es2016plus/