JS -- Variables As Properties

Posted 流畅的心情

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS -- Variables As Properties相关的知识,希望对你有一定的参考价值。

Variables As Properties 

When you declare a global javascript variable, what you are actually doing is defining a property of the global object . If you use var to declare the variable, the

当你声明一个全局变量,实际上,你是给全局对象定义了一个属性。如果你是用 var 声明的变量,

 

property that is created is nonconfigurable , which means that it cannot be deleted with the delete operator. We’ve already noted that if you’re not using strict mode

所创建的属性是不可配置的,也就是说不能用 delete 操作符 从全局对象中删除掉。在非严格模式下,

 

and you assign a value to an undeclared variable, JavaScript automatically creates a global variable for you.

给一个尚未声明的变量赋值,JS 会自动创建一个全局变量。

JavaScript global variables are properties of the global object, and this is mandated by the ECMAScript specification. There is no such requirement for local variables,

JS全局变量就是全局对象的属性,这是ECMAScript 规定的。局部变量虽然没有这样的规定,

but you can imagine local variables as the properties of an object associated with each function invocation. The ECMAScript 3 specification referred to this object as

但是局部变量是 函数调时创建的关联对象 的属性,ECMAScript 3 把这个 关联对象叫做 “call object”,

the“call object,” and the ECMAScript 5 specification calls it a “declarative environment record.” JavaScript allows us to refer to the global object with the this keyword,

而 ECMAScript 5  把这个关联对象叫做 “声明环境记录”。JS 允许我们通过  this 关键字 来应用全局对象,

but it does not give us any way to refer to the object in which local variables are stored. The precise nature of these objects that hold local variables is an

但是,没有任何办法去引用这个 调用时创建 的关联对象。实现这个关联对象具体细节,不用我们去关心,

implementation detail that need not concern us. The notion that these local variable objects exist, however, is an important one.

但是,重要的是,要知道有这样的一个关联对象存在。

以上是关于JS -- Variables As Properties的主要内容,如果未能解决你的问题,请参考以下文章

解决警告:FutureWarning: Pass the following variables as keyword args: x, y. From version 0.12(图文并茂详细版!!)

主题搜索结果

与 Keras、TensorFlow 和 scikit (tf.global_variables()) 可能存在的兼容性问题

AS3从外部文本文件加载变量

查询字段的默认值

JS继承之prototype