JavaScript 相当于 PHP 的 __get() 魔法方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3959187/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JavaScript's equivalent to PHP's __get() magic method
提问by Michal Pietrzyk
Possible Duplicate:
JavaScript getter for all properties
可能的重复:
所有属性的 JavaScript getter
Does JavaScript provide a method to access undefined object properties? In PHP the solution is to declare and implement __get()method in class.
Solutions using try { .. } catch { .. }are not sufficient for me, because I already have very large amount of code which actually needs to stay as-is.
JavaScript 是否提供访问未定义对象属性的方法?在 PHP 中,解决方案是__get()在类中声明和实现方法。
使用try { .. } catch { .. }的解决方案对我来说还不够,因为我已经有大量的代码实际上需要保持原样。

