JavaScript变量与属性 [英] JavaScript Variables vs Properties

查看:97
本文介绍了JavaScript变量与属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaScript中,全局变量也是窗口对象的属性。局部变量怎么样?它们是任何物体的属性吗?

In JavaScript a global variable is also a property of the window object. What about local variables? Are they the property of any object?

例如:

var apple=3;
alert(apple);                   //  3
alert(window.apple);            //  same

thing();

function thing() {
    var banana=4;
    alert(banana);              //  4
    alert(thing.banana);        //  doesn’t work, of course
}

banana 任何对象的属性

推荐答案


本地变量怎么样?它们是任何物体的属性吗?

What about local variables? Are they the property of any object?

否。当执行进入某个功能时,新的 声明性环境记录 用于存储标识符。

No. When execution enters a function, a new declarative environment record is created for storing the identifiers.

对象环境记录 (用于创建全局和 环境)没有变量映射到的用户空间对象。

Unlike object environment records (used for creating the global and with environments) there is no user space object to which the variables are mapped.

参见什么是声明性环境记录?它与激活对象有何不同?

这篇关于JavaScript变量与属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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