Detecting change in a Javascript Object

夙愿已清 提交于 2019-12-17 19:38:03

问题


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 function or a tricks to detect change on an entire Javascript Object ?


回答1:


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.




回答2:


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.




回答3:


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...



来源:https://stackoverflow.com/questions/11578377/detecting-change-in-a-javascript-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!