最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Imitate PHP's __get(), __set() & __call() magic methods in Node.js - Stack Overflow

programmeradmin0浏览0评论

I was wondering if there is a way to imitate PHP's magic methods __get() and __set() in Node. From this question: JavaScript getter for all properties I know you can do it in Rhino, but Node's built on V8. Does V8 have some way of doing this?

I was wondering if there is a way to imitate PHP's magic methods __get() and __set() in Node. From this question: JavaScript getter for all properties I know you can do it in Rhino, but Node's built on V8. Does V8 have some way of doing this?

Share Improve this question edited May 23, 2017 at 12:11 CommunityBot 11 silver badge asked Dec 31, 2010 at 19:54 MattMatt 22.9k25 gold badges85 silver badges118 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

No answer? Check out nowjs. They seem to have found a way to make __get() and __set() work in JavaScript. I can't figure out how they do it from the source code. :(

EDIT: Check out Monitor All JavaScript Object Properties (magic getters and setters)

I believe you're out of luck, at least as of March 2010. At least you have __defineGetter__ and __defineSetter__, though I realize that's not the same thing. In general I think using __noSuchMethod__/__get/method_missing is not good since it makes the code harder to read. Consider trying to get by without it and see if it makes your code clearer.

Have a look at my following answer that explains how one might tackle this with the use of ES6 proxies.

发布评论

评论列表(0)

  1. 暂无评论