JavaScript Global objects

Source: Internet
Author: User
Tags alphanumeric characters

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.