Javascript System Window object learning notes, javascript learning notes

Source: Internet
Author: User

Javascript System Window object learning notes, javascript learning notes

A window object is an ultimate javascript Object in a Web browser. It is at the very end of the scope and is an object that contains all objects. All attributes and functions defined in the global scope are properties of the window object.

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

1. Reference

There are usually two methods to reference the window object. The first is a simple reference to give the window object name; the second is to use the this keyword in the global scope.

Var foo = 'bar'; windowRef1 = window; windowRef2 = this; console. log (windowRef1, windowRef2); // outputs the reference console of the window object. log (windowRef1.foo, windowRef2.foo); // 'bar'

2. Features

The window object is implicit and is usually not explicitly referenced. Even if the window object is explicitly declared, It is also implicit because the window object is the last in the scope chain.

// Window. alert () and alert () statements are basically the same var foo = {// The window object is implicit here, window. foo fooMethod: function () {alert ('foo' + 'bar'); // The window object is implicit here. alert window. alert ('foo' + 'bar'); // explicitly calls the window object, with the same effect} foo. fooMethod (); // The window object is implicit here, window. foo. fooMethod ()

3. Attributes
Window objects have 18 attributes.

undefined NaN Infinity Boolean String Number Object Array Function Date RegExp Error EvalError RangeError ReferenceError SyntaxError TypeError URIError 

[Note] assigning undefined, NaN, and Infinity values is prohibited.

 4. Method

Javascript comes with some predefined functions, which are considered as the window object method.

1) encoding method

EncodeURI ():Encode the entire URI and replace all invalid characters with a special UTF-8

EncodeURI () has 82 unencoded characters:

! # $ & '() * +,-./:; =? @_~ 0-9 a-z A-Z
EncodeURIComponent ():Encode a section of the URI (often used to pass parameters through the GET method) and replace all invalid characters with a special UTF-8

In general, using encodeURIComponent () is more than encodeURI (), because in practice, it is more common to query string parameters rather than encoding the basic URI. EncodeURIComponent () has 71 unencoded characters:

! '()*-._~ 0-9 a-z A-Z
Escape ():Encode the string and convert the unicode encoding of the character into a hexadecimal sequence.

ES3 is opposed to the use of escape (), and it is recommended to use encodeURI and encodeURIComponent instead. However, escape () is still widely used in cookie encoding because escape () it Exactly encodes invalid characters in the cookie and does not encode the common "/" in the path. Escape () has 69 unencoded characters:

* +-./@ _ 0-9 a-z A-Z
DecodeURI ():Decode encodeURI ()

DecodeURIComponent ():Decode encodeURIComponent ()

Unescape ():Decode escape ()

var uri = "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%23startvar uri = '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 complete ECMAScript parser that accepts only one parameter, that is, the JavaScript string to be executed. When the parser finds that the eval () method is called in the code, it will parse the passed parameters as the actual ECMAScript statement, and then insert the execution result to the original position. The eval () method is powerful but dangerous to interpret strings. When using it to execute user input data, malicious users may enter the code that threatens the website or application characters, which is called code injection.

[Note] in strict mode, if you do not have external access to any variables or functions created in eval (), assigning values to eval will also cause errors.

2) Digital Method

There are four numeric methods under the Window object: isFinite (), isNaN (), parseFloat (), and parseInt ().

The above is all the content of this article, hoping to help you learn.

Articles you may be interested in:
  • Window objects in JavaScript
  • Javascript trap window Global Object
  • Detailed parsing of js window. event objects
  • Javascript window object attribute sorting
  • Js Code used to determine whether the object is a window
  • Document Object and window object in JavaScript
  • Detailed Arrangement of javascript Window and document objects
  • Descriptions of top, parent, and opener of JS window objects

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.