Detecting change in a Javascript Object

后端 未结 3 441
Happy的楠姐
Happy的楠姐 2020-12-10 11:35

I found this gist to detect changes on specified fiels of a object : https://gist.github.com/3138469

But it bind an event only on one field.

Someone know a f

相关标签:
3条回答
  • 2020-12-10 12:12

    2019 Update: These days this can be achieved using Proxy API in a much more efficient manner. The on-change library uses the Proxy API behind the scene to make this even easier.

    2012 Update: I've just noticed that the author of Watch.js is referencing a library with much broader browsers' support. MultiGetSet.JS

    When I want to achieve this I usually use Watch.js, you can watch a whole object or one attribute.

    0 讨论(0)
  • 2020-12-10 12:12

    This is currently not possible, you can only define getters/setters for individual properties.

    Yet, there is a draft for Proxy objects which could do that. Today, it is only supported in Firefox' Javascript 1.8.5.

    0 讨论(0)
  • 2020-12-10 12:23

    This is not possible using watch.js. it just detect the changes of an object or the attributes of the object. It DOESNT detect if we add an attribute to the object or change a new added attribute...

    0 讨论(0)
提交回复
热议问题