Hacker News new | ask | show | jobs
by emehrkay 3263 days 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
2 comments

I'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

Could 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?
theres defineproperty in es5. ive used it to create a orm where foo.bar = 1 executes async sql: update foo set x=1
That sounds pretty cool. Are there any public examples that I can learn from? Thanks
I'd also love to see examples.