Home > Article > Web Front-end > Learn about JavaScript global objects in a few minutes: predefined objects
Global objects are predefined objects that serve as placeholders for JavaScript’s global functions and global properties. By using the global object, you can access all other predefined objects, functions, and properties. The global object is not a property of any object, so it has no name.
In top-level JavaScript code, you can use the keyword this to refer to the global object. But there is usually no need to reference the global object in this way, because the global object is the head of the scope chain, which means that all unqualified variable and function names will be queried as properties of the object. For example, when JavaScript code refers to the parseInt() function, it refers to the parseInt property of the global object. The global object is the head of the scope chain, which also means that all variables declared in the top-level JavaScript code will become properties of the global object.
The global object is just an object, not a class. There is neither a constructor nor the ability to instantiate a new global object.
When JavaScript code is embedded in a special environment, the global object usually has environment-specific properties. In fact, the ECMAScript standard does not specify the type of global objects. JavaScript implementations or embedded JavaScript can treat any type of object as a global object, as long as the object defines the basic properties and functions listed here. For example, in a JavaScript implementation that allows Java to be scripted via LiveConnect or related technologies, the global object is given the java and Package properties listed here and the getClass() method. In client-side JavaScript, the global object is the Window object, which represents the web browser window that allows JavaScript code.
decodeURI() 解码某个编码的 URI。 decodeURIComponent() 解码一个编码的 URI 组件。 encodeURI() 把字符串编码为 URI。 encodeURIComponent() 把字符串编码为 URI 组件。 escape() 对字符串进行编码。 eval() 计算 JavaScript 字符串,并把它作为脚本代码来执行。 getClass() 返回一个 JavaObject 的 JavaClass。 isFinite() 检查某个值是否为有穷大的数。 isNaN() 检查某个值是否是数字。 Number() 把对象的值转换为数字。 parseFloat() 解析一个字符串并返回一个浮点数。 parseInt() 解析一个字符串并返回一个整数。 String() 把对象的值转换为字符串。 unescape() 对由 escape() 编码的字符串进行解码。
Related articles:
What is a JavaScript global object? What properties does the global object have?
Introduction to global objects in JavaScript
The above is the detailed content of Learn about JavaScript global objects in a few minutes: predefined objects. For more information, please follow other related articles on the PHP Chinese website!