JavaScript#39;s equivalent to PHP#39;s __get() magic method(JavaScript 相当于 PHP 的 __get() 魔法方法)
问题描述
可能的重复:
所有属性的 JavaScript getter
JavaScript 是否提供访问未定义对象属性的方法?在 PHP 中,解决方案是在类中声明并实现 __get()
方法.
使用 try { .. } catch { .. }
的解决方案对我来说是不够的,因为我已经有大量的代码实际上需要保持原样.
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.
推荐答案
您可以选择编写一个类似的功能并根据 参数 数组.我不是 100% 认为这会解决您的问题.
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() 魔法方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:JavaScript 相当于 PHP 的 __get() 魔法方法


基础教程推荐
- 使用 PDO 转义列名 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- PHP 守护进程/worker 环境 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01