JavaScript变量与属性

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

例如:

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
}

香蕉是任何物体的财产

最佳答案

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

当执行进入功能时,会创建一个新的declarative environment record用于存储标识符.

object environment records(用于创建全局和环境)不同,没有用于映射变量的用户空间对象.

另见What really is a declarative environment record and how does it differ from an activation object?

转载注明原文:JavaScript变量与属性 - 代码日志