3

How to use Object.observe on Map? This doesn't work:

var map = new Map();
Object.observe(map, function() { console.log("ok"); });
map.set('key', 'value');

And this too:

var map = new Map();
Array.observe(map, function() { console.log("ok"); });
map.set('key', 'value');
robsch
  • 8,466
  • 8
  • 56
  • 87
monkey
  • 1,099
  • 13
  • 15
  • 1
    Basically a duplicate of [Observing changes to ES6 Maps and Sets](http://stackoverflow.com/q/29909823/218196) – Felix Kling May 09 '15 at 17:49

1 Answers1

3

The Object.observe() facility is a general way to watch for changes to an object. Calls to the Map API do not trigger any of the events that the .observe() facility watches for, because no properties of the Map object are added, remove, changed, etc.

Current ES6/ES2015 specs make no provisions for observing updates to Map or Set instances, as far as I can tell.

Pointy
  • 371,531
  • 55
  • 528
  • 584