4 ms·
I'd like to be able to capture object modifications like Python's magic __getattr__ __setattr__ __delattr__ and calling methods that do not exist on objects. In
by emehrkay 9y ago
I'd like to be able to capture object modifications like Python's magic __getattr__ __setattr__ __delattr__ and calling methods that do not exist on objects. In the meantime I am writing a get, set, delete method on my object and using those instead
- tkone 9y agoThis is what Proxy[1] is for. [1] https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- emehrkay 9y agoI've used Proxy in the past. It doesn't allow for the capture of both `object.attr_does_not_exist` and `object.methodDoesNotExist()` simultaneously, it is one or the other. I will admit that I am trying to use another lang's paradigms in JS, but only because it is so similar and it makes sense to me. But I may be able to use Proxy just to capture object changes. I will try it out
- houli 9y agoCould you have your "get" handler do its thing and have it forward on the arguments it received to the "apply" handler if necessary with an extra flag argument and vice versa?
- ngz00 9y agoCheck this out: https://gist.github.com/torgeir/e528337e7a9a41c96ac9 https://gist.github.com/torgeir/e528337e7a9a41c96ac9
- z3t4 9y agotheres defineproperty in es5. ive used it to create a orm where foo.bar = 1 executes async sql: update foo set x=1
- emehrkay 9y agoThat sounds pretty cool. Are there any public examples that I can learn from? Thanks
- silviogutierrez 9y agoI'd also love to see examples.