Autovivification 和 Javascript
自动生存是否只与“取消引用”未定义的结构有关,因为在 JavaScript 中,如果您指定不存在的索引或属性,它不会动态创建它吗?但这不是自动生存吗,因为您必须首先将底层结构声明为对象或数组?
Does autovivification only have to do with "derefencing" undefined structures, because in JavaScript if you specify a index or a property that doesn't exist won't it dynamically create it? But is this not autovivification because you must declare the underlying structure to first be an object or an array?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
命名空间是 JavaScript 中自动生存可能派上用场的领域之一。目前,要为对象“命名空间”,您必须执行以下操作:
如果 JavaScript 支持自动生存,则不需要第一行。 JavaScript 中向对象添加任意属性的能力是由于它是一种动态语言,但并不完全是自动生存。
Namespacing is one area where autovivification might be handy in JavaScript. Currently to "namespace" an object, you have to do this:
Were autovivification supported by JavaScript, the first line would not be necessary. The ability to add arbitrary properties to objects in JavaScript is due to its being a dynamic language, but is not quite autovivification.
ES6的
Proxy
可以用来实现autovivification,测试:
ES6's
Proxy
can be used for implementing autovivification,Test: