Home > Article > Web Front-end > A brief analysis of two types of global objects/functions in JavaScript_javascript skills
The JavaScript mentioned here refers to the browser environment including the host environment. The first is the ECMAScript Global Object, and the second is the global object/function under the host environment (Host).
1. Core JavaScript built-in objects, that is, objects provided by ECMAScript implementation that do not depend on the host environment
These objects already exist (instantiated) before the program is executed. ECMAScript is called The Global Object and is divided into the following types
1, Value Properties of the Global Object. There are NaN, Infinity, undefined.
2, Function Properties of the Global Object. There are eval, parseInt, parseFloat, isNaN, isFinite, decodeURI, encodedURI, encodeURIComponent
3, Constructor Properties of the Global Object (Constructor Properties of the Global Object). There are Object, Function, Array, String, Boolean, Number, Date, RegExp, Error, EvalError, RangeError, ReferenceError, SyntaxError, TypeError, URIError.
4. Other Properties of the Global Object can be seen as static classes in Java, and can be used directly with the class name, dot, and method name. There is Math, JSON.
The ECMAScript specification mentions that these global objects (The Global Object) have Writable properties, that is, Writable is true, and enumerable (Enumerable) is false, that is, for in enumeration cannot be used. ECMAScript has this section
Unless otherwise specified, the standard built-in properties of the global object have attributes {[[Writable]]: true, [[Enumerable]]: false, [[Configurable]]: true}.
Although the specification mentions that The Global Object can be rewritten, no one will rewrite them. This is just a test.
The results show that except NaN which cannot be rewritten in IE9 (pre3)/Safari, everything else has been rewritten. Here are just four. If you are interested, you can test all the above The Global Objects one by one. The point here is that core JavaScript built-in objects can generally be overridden, although no one does this.
Test its enumerability below
2. Global objects/functions provided by the host environment
Such as window, alert, setTimeout, document, location, etc., most browsers will restrict their rewriting
Rewrite alert
The following are two ways to declare global variables