Simulate PHP __get (), __set () and __call () magic methods in Node.js

I was wondering if there is a way to emulate the PHP magic methods __get () and __set () in Node. From this question: JavaScript getter for all properties I know you can do this in Rhino, but Node is built on V8. Is there a way for V8 to do this?

+3
source share
3 answers

No answer? Check out nowjs. They seemed to find a way to make __get () and __set () work in JavaScript. I can not understand how they do it from the source code. :(

EDIT: Check out Monitoring all the properties of a JavaScript object (magic getters and setters)

+2
source

, , 2010 . , __defineGetter__ __defineSetter__, , . , , __noSuchMethod__/__get/method_missing , . , .

+3

See my next answer , which explains how to solve this problem with ES6 Proxy .

0
source

Source: https://habr.com/ru/post/1782954/


All Articles