window of the JavaScript type system

Source: Internet
Author: User

Table of Contents [1] reference [2] attribute [3] Property [4] Method encoding method eval () number method in front of the words

The Window object is the ultimate backstop object of JavaScript in a Web browser, at the very end of the scope, and is an object that contains all objects. All properties and functions defined in the global scope are properties of the Window object

var mystringvar = ' myString '; var function () {};console.log ( in window); // true  in window); // true

Reference

There are usually two methods of referencing a Window object. The first is the name given to the Window object by a simple reference, and the second is the use of the This keyword in the global scope

var foo = ' Bar '=this; Console.log (WINDOWREF1,WINDOWREF2); // the Output Window object's Reference Console.log (Windowref1.foo,windowref2.foo); // ' Bar '

Characteristics

The Window object is implicit, usually not explicitly referenced, and even if the Window object is explicitly declared, it is implicitly because the Window object is the last in the scope chain

// the Window.alert () and alert () statements are basically the same var foo = {//Window object is implicit here, Window.foo    function() {        alert (' Foo ' + ' bar '); // The Window object is implicit here, Window.alert        Window.alert (' foo ' + ' bar '); // explicitly invokes the Window object as if it were an effect     }}foo.foomethod (); // The Window object is implicit here, Window.foo.fooMethod ()

Property

There are 18 properties in the Window object

Undefined NaN Infinity  Boolean String number Object Array Function Date RegExp Error evalerror rangeerror referenceerr or SyntaxError TypeError urierror    

[note] Assigning values to undefined, Nan, and infinity are forbidden

Method

JavaScript comes with some predefined functions that are considered a method of the Window object

Encoding method

encodeURI (): Encodes the entire URI and replaces all invalid characters with a special UTF-8

There are 82 non-encoded characters for encodeURI ():

! # $ & ' () * +,-. / : ; = ? @ _ ~ 0-9 A-Z

encodeuricomponent (): Encodes a segment of a URI (commonly used to pass parameters to a Get method), replacing all invalid characters with a special UTF-8

In general, use encodeURIComponent () more than encodeURI (), because in practice it is more common to query string parameters than to encode the underlying URI. There are 71 non-encoded characters for encodeURIComponent ():

!  ' ( ) * - . _ ~ 0-9 A-Z

Escape (): encodes a string to convert the Unicode encoding of a character into a 16-binary sequence

ES3 is opposed to the use of escape () and is recommended to replace with encodeURI and encodeURIComponent, but escape () is still widely used for encoding cookies because escape () The illegal characters in the cookie are encoded exactly and the "/" that is often present in the path is not encoded. There are 69 non-encoded characters for Escape ():

* + - . /@ _ 0-9 A-Z

decodeURI (): Decode encodeURI ()

decodeuricomponent (): Decode encodeURIComponent ()

unescape (): Decode Escape ()

varURI = "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%23startConsole.log (Escape (URI));//Http%3a//www.wrox.com/illegal%20value.htm%23startvarURI = ' Http%3a%2f%2fwww.wrox.com%2fillegal%20value.htm%23start '; Console.log (decodeURI (URI));//Http%3a%2f%2fwww.wrox.com%2fillegal Value.htm%23startConsole.log (decodeURIComponent (URI));//Http://www.wrox.com/illegal Value.htm#startConsole.log (Unescape (URI));//Http://www.wrox.com/illegal Value.htm#start

Eval ()

The eval () method is like a full ECMAScript parser that accepts only one parameter, the JavaScript string to execute. 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 execution result into the original location. The ability of the eval () method to interpret strings is very powerful, but also very dangerous. When using it to perform user input data, malicious users may enter code that threatens site or application characters, which is called Code injection

[note] in strict mode, external access does not have any variables or functions created in eval (), and assigning a value to eval also results in an error

Digital method

The four methods of Isfinite (), IsNaN (), parsefloat (), parseint () are also available under the Window object.

Detailed information about them is here

window of the JavaScript type system

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.