The Window object is the ultimate fallback object of JavaScript in a Web browser, at the very end of the scope, and is an object that contains all the objects. All properties and functions defined in the global scope are properties of the Window object
var mystringvar = ' myString ';
var Myfunctionvar = function () {};
Console.log (' Mystringvar ' in Windows);//true
console.log (' Myfunctionvar ' in window);//true
1, reference
There are usually two ways to reference a Window object. The first is a simple reference to the name of the Window object, and the second is to use the This keyword in the global scope
var foo = ' Bar ';
windowRef1 = window;
WindowRef2 = this;
Console.log (WINDOWREF1,WINDOWREF2);//Output Window object's Reference
Console.log (Windowref1.foo,windowref2.foo);//' Bar ' Bar
2, characteristics
The Window object is implicit, usually not explicitly referenced, and is implicit even if the Window object is explicitly declared, because the Window object is the last in the scope chain
The Window.alert () and alert () statements are essentially the same
var foo = {//window objects are implicitly here, Window.foo
foomethod:function () {
alert (' foo ' + ' bar '); The//window object is implicit here, Window.alert
window.alert (' foo ' + ' bar ');//Explicitly call the Window object, the effect is the same
}
}
Foo.foomethod ();//window object is implicit here, Window.foo.fooMethod ()
3, properties
There are 18 properties for the Window object
Undefined NaN Infinity
Boolean String number Object Array Function Date RegExp
Error evalerror rangeerror refere Nceerror SyntaxError TypeError Urierror
[note] Prohibit assigning values to undefined, Nan, and infinity
4. Methods
JavaScript comes with predefined functions that are considered methods of Window objects
1), coding method
encodeURI (): encodes the entire URI, replacing all invalid characters with a special UTF-8
encodeURI () has 82 characters that are not encoded:
! # $ & ' () * +,-. / : ; = ? @ _ ~ 0-9 A-Z
encodeuricomponent (): encodes a section of a URI (used to pass arguments to a GET method) and replaces all invalid characters with a special UTF-8
In general, the use of encodeURIComponent () is more than encodeURI (), because it is more common in practice to query string parameters than to base URI encoding. encodeURIComponent () has 71 characters that are not encoded:
! ' ( ) * - . _ ~ 0-9 A-Z
Escape (): encodes a string to convert the Unicode encoding of a character into a 16-in sequence
The use of ES3 against Escape () is recommended and replaced with encodeURI and encodeURIComponent, but escape () is still widely used in the encoding of Cookies because escape () The illegal character in the cookie is encoded and the "/" that is often present in the path is not encoded. There are 69 characters that are not encoded in Escape ():
* + - . /@ _ 0-9 A-Z
decodeURI (): decoding encodeURI ()
decodeuricomponent (): decoding encodeURIComponent ()
unescape (): decoding Escape ()
var uri = "Http://www.wrox.com/illegal value.htm#start";
Console.log (encodeURI (URI));//http://www.wrox.com/illegal%20value.htm#start
Console.log (encodeuricomponent (URI)); /http%3a%2f%2fwww.wrox.com%2fillegal%20value.htm%23start
Console.log (Escape (URI));//http%3a//www.wrox.com/ Illegal%20value.htm%23start
var uri = ' Http%3a%2f%2fwww.wrox.com%2fillegal%20value.htm%23start ';
Console.log (decodeURI (URI));//http%3a%2f%2fwww.wrox.com%2fillegal Value.htm%23start
Console.log ( decodeURIComponent (URI));//http://www.wrox.com/illegal Value.htm#start
console.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, the JavaScript string to execute. When the parser discovers that the eval () method is invoked in the code, it parses the incoming argument as the actual ECMAScript statement, and then inserts the execution result into the original location. The eval () method's ability to interpret strings is very powerful, but it is also very dangerous. When you use it to execute user input data, there may be malicious users to enter the threat site or application characters code, is called code injection
[note] in strict mode, external access to any variable or function created in eval () is not available, and assigning a value to Eval can result in an error
2), Digital methods
The window objects also have Isfinite (), isNaN (), parsefloat (), parseint (), and the four methods for numbers
The above is the entire content of this article, I hope to help you learn.