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
  • 13,364
  • 2
  • 47
  • 55
Taron Mehrabyan
  • 2,199
  • 2
  • 20
  • 27

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
  • 310,957
  • 84
  • 592
  • 636