MDN for Object.Observe says that Observe is now obsolete and we should use "more general Proxy object instead".
But Observe allowed to intercept changes on existing object. If Proxy does not allow then Proxy API is not "more general" than Observable API.
MDN for Proxy and this question give examples of intercepting changes to proxy object, but never talk about changes to underlying object.
Is Proxy supposed to intercept changes to underlying object in current or future ECMA standard ?
Example:
let o = {};
let p = new Proxy(o, { set: (target, prop, val)=> console.log(target, prop, val) });
p.p1 = 'v1'; // this will log o, "p1", "v1"
o.p2 = 'v2'; // is this supposed to log o, "p2", "v2" in ECMA standard ?
No, using that particular pattern.
Set the value at the
Proxy
object, and value will be set attarget
object.Though you can also define
getter
at original object.