As Yoshi stated in a comment, this is possible using Object.observe() from the ES7 project.
However, this is not exactly a "catcher", because it will be called only after the property has changed, and not earlier. So, if you want to save the property somewhere else, you will need to delete it. Since the observe is asynchronous, it will be launched after the current call, which means that the new value can be used immediately before the change.
In addition, Chrome is just now.
The following snippet does some manipulation of the object using the built-in parameter and uses Object.observe . It is registered in the following order:
- I added this value: foobar
- Callback Retrieves: foobar
- Foo.bar value after deletion: undefined
Here:
var foo = {}; Object.observe(foo, function(changes) { var lastChanges = changes[changes.length - 1], newValue = lastChanges.object[lastChanges.name]; console.log('The callback retrieves: ' + newValue); delete lastChanges.object[lastChanges.name]; }, ['add']); foo.bar = 'foobar';
Due to the fact that in the ES7 project, the previous one may be completely wrong depending on when you read this.
Paul stenne
source share