1

I have JavaScript array which is consists of many objects.

var array=[{name:1},{name:2}.....]

I want to use Object.observe to handle data changes on each of these objects.

Is there any way to apply something like event delegation here , in order to not apply observe for each of objects?

If I use Object.observe for array itself than changing its items doesn't trigger anything.

vkurchatkin
  • 12,170
  • 2
  • 40
  • 50
Taron Mehrabyan
  • 2,079
  • 2
  • 18
  • 22

1 Answers1

0

No, that's not possible.

Imagine code like this:

var foo = {...};
var bar = [foo, {..}, {..}, {..}]
Object.yourWeirdMagicObserve(bar, ..);

Would changing foo trigger your callback now? Or only modifications to bar[0]? When you use bar[0] the object is retrieved from bar but besides that it has no association with bar whatsoever.

ThiefMaster
  • 285,213
  • 77
  • 557
  • 610