自主化和Javascript [英] Autovivification and Javascript

查看:101
本文介绍了自主化和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?

推荐答案

Namespacing是JavaScript中可以自动进行生存的一个区域.当前要命名"对象,您必须执行以下操作:

Namespacing is one area where autovivification might be handy in JavaScript. Currently to "namespace" an object, you have to do this:

var foo = { bar: { baz: {} } };
foo.bar.baz.myValue = 1;

JavaScript支持自动生存,第一行不是必需的.之所以能够在JavaScript中向对象添加任意属性,是因为它是一种动态语言,但并不能完全自动实现.

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.

这篇关于自主化和Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆