简体   繁体   English

检测Javascript对象中的更改

[英]Detecting change in a Javascript Object

I found this gist to detect changes on specified fiels of a object : https://gist.github.com/3138469 我找到了这个要点来检测对象的指定fiels的变化: 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 ? 有人知道一个函数或技巧来检测整个Javascript对象的变化吗?

2019 Update: These days this can be achieved using Proxy API in a much more efficient manner. 2019更新:这些天可以使用Proxy API以更有效的方式实现。 The on-change library uses the Proxy API behind the scene to make this even easier. 变更库使用场景后面的Proxy API使这更容易。

2012 Update: I've just noticed that the author of Watch.js is referencing a library with much broader browsers' support. 2012年更新:我刚刚注意到Watch.js的作者正在引用一个拥有更广泛浏览器支持的库。 MultiGetSet.JS MultiGetSet.JS

When I want to achieve this I usually use Watch.js , you can watch a whole object or one attribute. 当我想要实现这一点时,我通常使用Watch.js ,您可以观看整个对象或一个属性。

This is currently not possible, you can only define getters/setters for individual properties. 目前这是不可能的,您只能为各个属性定义getter / setter。

Yet, there is a draft for Proxy objects which could do that. 然而,有一个Proxy对象的草案可以做到这一点。 Today, it is only supported in Firefox' Javascript 1.8.5 . 今天,它仅在Firefox的Javascript 1.8.5中得到支持

This is not possible using watch.js. 使用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... 它DOESNT检测我们是否向对象添加属性或更改新添加的属性...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM