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

Direct ProxiesでObject.observeの Polyfillはできるのか

Direct ProxiesでObject.observeの Polyfillはできるのか

18b12f8f7910445b2637f0f21f59d467?s=128

Kazuhito Hokamura

December 18, 2014
Tweet

Transcript

  1. Direct ProxiesͰObject.observeͷ Polyfill͸Ͱ͖Δͷ͔

  2. None
  3. Object.observe Object.observe(obj, (changes) => { // do something
 }); •

    objΛมߋ͢Δͱhandlerؔ਺͕ݺ͹ΕΔ
  4. Direct Proxies var proxy = new Proxy(obj, {
 set(target, name,

    val, receiver) { // do something
 } }); • objΛҾ਺ͱͯ͠৽ͨͳ୅ཧΦϒδΣΫτʢproxyʣΛಘΔ • proxyΛૢ࡞ͨ࣌͠ʹhandler͕ݺ͹ΕΔ • objΛૢ࡞ͯ͠΋handler͸ݺ͹Εͳ͍
  5. ͜ͷAPIΛPolyfill͢Δ ͷ͸ແཧͰ͸ɾɾʁ Object.observe(obj, (changes) => { // do something
 });

  6. ProxyͷPolyfillϥΠϒϥϦ

  7. None
  8. harmony-reflect/examples/observer.js

  9. ͍͚ͦ͏ʂʂ

  10. ͳΜ͔ΤϥΔɾɾ // Firefox 36.0 Observer(Object); // enable polyfill var obj

    = {}; Object.observe(obj, handler); //=> uncaught exception: can only get notifier of observable objects, given [object Object]
  11. ͜͏͢Δඞཁ͕͋ΔΒ͍͠ var obj = {}; var o = Object.createObservable(obj); Object.observe(o,

    handler);
  12. Q: Direct ProxiesͰObject.observeͷ Polyfill͸Ͱ͖Δͷ͔

  13. A:ʢͨͿΜʣແཧ

  14. ͋Γ͕ͱ͏͍͟͝·ͨ͠ɻ