JS -- Variables As Properties
2018-06-24 00:24:12来源:未知 阅读 ()
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.
但是,重要的是,要知道有这样的一个关联对象存在。
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- js中Object.defineProperty()和defineProperties() 2018-06-24
- JS--Testing Properties 判断属性是否在对象里 2018-06-24
- csharp: Setting the value of properties reflection 2018-06-23
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash