2

Javascript proxies are supposed to be the "more general" replacement for Object.observe, but one nice thing about Object.observe was that it let you monitor unintended changes. It could be used as a convenience method for debugging legacy code, for example. Proxies don't seem to function the same way; they only intercept interactions that happen through the proxy. Am I missing something?

rswerve
  • 119
  • 2
  • 6
  • `Javascript proxies are supposed to be the "more general" replacement for Object.observe` what makes you say that? – Jaromanda X Sep 12 '17 at 02:36
  • 1
    The docs for Object.observe. `You can use the more general Proxy object instead.` – rswerve Sep 12 '17 at 02:38
  • Sorry, I only read proxy docs :p of course, Object.observe is obsolete, so you shouldn't be using it at all – Jaromanda X Sep 12 '17 at 02:42
  • Correct. But it seems the putative replacement for the obsolete method doesn't offer some of the old functionality. – rswerve Sep 12 '17 at 02:44
  • I see where you're coming from. Can you perhaps post some code you use `Object.observe` for which you can't use proxy instead? Maybe someone will be able to help with a specific example – Jaromanda X Sep 12 '17 at 02:47
  • The linked docs actually have good examples. You can put an observer directly on an object, and log out any changes. Proxy requires interactions to go through the handler. – rswerve Sep 12 '17 at 02:49
  • however, couldnt all of the `Object.observe` cases be covered in a handler. you could create a `get` a `set` handler that logs every property accessed, and wrap it on an existing library like say jquery `jquery = new Proxy(jquery, handler)` and get the same result. – Ja Superior Dec 28 '17 at 06:11
  • 3 years later, still no replacement to `Object.observe` – David Alsh Nov 17 '20 at 10:22

0 Answers0