简体   繁体   English

javascript中的全局属性是什么意思

[英]what is global properties means in javascript

Today I'm reading "javascript the definitive guide."今天我正在阅读“javascript 权威指南”。 in chapter 3.5 talk about the global object.There said:在3.5章讲全局对象。有说:

global properties like undefined, infinity, and NaN全局属性,如 undefined、infinity 和 NaN

Because of my lack knowledge, I feel I could not understand it.由于我的知识不足,我觉得我无法理解。 In my mind, I feel undefined Infinity and NaN are values I don't know how could these are properties.在我看来,我觉得 undefined Infinity 和 NaN 是我不知道这些属性的值。 Thanks for any thoughts.感谢您的任何想法。

wow javascript is so confusing I just check this:哇 javascript 太混乱了,我只是检查一下:
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/undefined

undefined is a property and this property value is also undefined. undefined 是一个属性,这个属性值也是未定义的。
if this understanding is wrong please correct me.如果这种理解是错误的,请纠正我。

It simply means that they could be used in anywhere of your code at any time, ie, they are always available to you in any scope of code.这只是意味着它们可以随时用于您代码的任何地方,即,它们始终在任何代码范围内可供您使用。

Reference: http://www.w3schools.com/jsref/jsref_obj_global.asp参考: http : //www.w3schools.com/jsref/jsref_obj_global.asp

Properties of the global object are properties you can use anywhere without specifying the object全局对象的属性是您可以在任何地方使用而无需指定对象的属性

  • Instead of window.undefined you can write undefined你可以写undefined而不是window.undefined
  • Instead of window.console.log you can write console.log您可以编写console.log而不是window.console.log
  • etc...等等...

The Global properties refers the variables that can be used anywhere throughout the document and need not be declared.全局属性指的是可以在整个文档中的任何地方使用并且不需要声明的变量。

I would provide you this standard ECMA Language Specification for complete reference.我会为您提供这个标准的 ECMA 语言规范以供完整参考。


  1. Update: For Down voters.更新:对于唐选民。

The reason to provide ECMA as a reference is here提供ECMA作为参考的原因在这里


  1. Update: undefined is a property and this property value is also undefined.更新:未定义是一个属性,这个属性值也是未定义的。

Your understanding this perfectly correct.你的理解完全正确。


Explanation is as:解释如下:

  • undefined value未定义的值

     primitive value used when a variable has not been assigned a value
  • Undefined type未定义类型

     type whose sole value is the undefined value

as mentioned in the above standard link in sections 4.3.9 and 4.3.10 .如上述第4.3.94.3.10节中的标准链接所述。 I was trying to convey this message but I posted just the link.我试图传达这条信息,但我只发布了链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM