JavaScript等价于PHP的__get()魔术方法 [英] JavaScript's equivalent to PHP's __get() magic method
问题描述
可能存在重复:
所有属性的JavaScript getter
JavaScript是否提供方法访问未定义的对象属性?在PHP中,解决方案是在类中声明和实现 __ get()
方法。 {...} 对我来说是不够的,因为我已经有非常多的代码需要保持原样。
您可以选择编写类似的功能,并根据参数数组。我不是100%,这将解决您的问题。
Possible Duplicate:
JavaScript getter for all properties
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.
You may choose to write a similar functionality and check existing parameters them against the arguments array. I'm not 100% that this will solve your problem.
这篇关于JavaScript等价于PHP的__get()魔术方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!