Global Object
The most specific object in the global object ECMAScript, because from that point of view, the object is not present.
IsNaN (), Isfinite (), parseint (), and parsefloat () are all actually methods of the global object. In addition to this, global also contains other methods.
1.URI Encoding method
The encodeURI () and encodeURIComponent () methods can encode URLs for sending to a browser.
The encodeURI () method allows you to encode a URL with a hollow lattice character
The encodeURIComponent () method can replace non-alphanumeric characters in a URL with character encoding
The decodeURI () method converts a space character encoding in a URL to a character that corresponds to a encodeuri ()
The decodeURIComponent () method converts all non-alphanumeric character encodings in a URL to characters that correspond to encodeURIComponent ()
The 2.eval () method is hailed as the most powerful method
The eval () method parses and executes the incoming string code with the ECMAScript parser. Accept only one parameter
Eval () execution method takes too long to run
When the parser discovers that the eval () method is called in the code, it parses the passed-in parameter as the actual ECMAScript statement, and then inserts the result of the execution into the original location. Code executed through the eval () method is considered part of the execution environment that contains the call, so the executed code has the same scope chain as the execution environment.
Properties of 3.Global Objects
Property |
Description |
Undefined |
Special value undefined |
NaN |
Special Value Nan |
Infinity |
Special Value Infinity |
Object |
Constructor Object |
Array |
Constructor array |
Function |
constructor function |
Boolean |
Constructor Boolean |
String |
Constructor string |
Number |
Constructor number |
Date |
Constructor date |
Regexp |
Constructor RegExp |
Error |
Constructor error |
Evalerror |
Constructor Evalerror |
Rangeerror |
Constructor Rangeerror |
Referenceerror |
Constructor Referenceerror |
SyntaxError |
Constructor SyntaxError |
TypeError |
Constructor TypeError |
Urierror |
Constructor Urierror |
//1.URI Encoding MethodvarURI = "Http://www.wrox.com/illegal Value.htm#start"; Console.log (encodeURI (URI));//Http://www.wrox.com/illegal%20value.htm#startConsole.log (encodeURIComponent (URI));//Http%3a%2f%2fwww.wrox.com%2fillegal%20value.htm%23startURI= "Http%3a%2f%2fwww.wrox.com%2fillegal%20value.htm%23start"; Console.log (decodeURI (URI)); Console.log (decodeURIComponent (URI ));//2.eval () methodConsole.time ("Eval1"); Eval ("Console.log (' Hi ')"); Console.timeend (' Eval1 '); Eval ("Console.log (decodeURI (URI))");//eval () ability to parse strings is very powerful, but also very dangerous. Therefore, you must be extremely cautious when using eval (), especially if you are using it to perform user input data. //4. Window Objectvarcolor = "Red";functionSaycolor () {console.log (window.color);} Window.saycolor ();//another way to get a global objectvarGlobal =function (){return This;} (); Console.log (global)
View Code
JavaScript Global objects