The window object is the ultimate bottom-up object of JavaScript in web browsers. It is at the 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
1. Reference
There are usually two types of references to window Object methods. The first is to simply reference the name given to the window object; the second is to use the this keyword in the global scope
var foo ='bar'; windowRef1 = window; windowRef2 = this; console.log(windowRef1,windowRef2);//输出window对象的引用 console.log(windowRef1.foo,windowRef2.foo);//'bar' 'bar'
2, characteristics
The window object is implicit and is usually not referenced explicitly; even if the window object is explicitly declared, it is implicit because the window object is the last one in the scope chain
//window.alert()和alert()语句基本上是相同的 var foo = {//window对象在这里是隐式的,window.foo fooMethod: function(){ alert('foo' + 'bar');//window对象在这里是隐式的,window.alert window.alert('foo' + 'bar');//显式调用window对象,效果一样 } } foo.fooMethod();//window对象在这里是隐式的,window.foo.fooMethod()
3. Properties
The window object has a total of 18 properties
##
undefined NaN Infinity Boolean String Number Object Array Function Date RegExp Error EvalError RangeError ReferenceError SyntaxError TypeError URIError
4. Methods
1), encoding method
encodeURI():Encode the entire URI, using special UTF -8 Replace all invalid characters
encodeURI() has 82 unencoded characters:! # $ & ' ( ) * + , - . / : ; = ? @ _ ~ 0-9 a-z A-Z
encodeURIComponent():Encode a certain segment of the URI (commonly used for passing parameters in the GET method ), replacing all invalid characters with the special UTF-8
! ' ( ) * - . _ ~ 0-9 a-z A-Z
escape():Encode the string and convert the unicode encoding of the characters into a hexadecimal sequence
##* + - . / @ _ 0-9 a-z A-Z
decodeURI():Decode encodeURI()
decodeURIComponent():Decode encodeURIComponent()
unescape():Decode escape()
eval() The eval() method is like a complete The ECMAScript parser accepts only one parameter, the JavaScript string to be executed. When the parser finds that the eval() method is called in the code, it will parse the incoming parameters as actual ECMAScript statements, and then insert the execution results into the original position. The eval() method's ability to interpret strings is very powerful, but also very dangerous. When it is used to perform user input data, a malicious user may enter code that threatens the site or application characters, which is the so-called code injection
[Note] In strict mode, eval() is not accessible from the outside. For any variable or function created in, assigning a value to eval will also cause an error
2), digital method There is also isFinite under the Window object (), isNaN(), parseFloat(), parseInt(), these four methods about numbers
The above is the detailed content of Detailed explanation of javascript window object references, characteristics, properties, and methods. For more information, please follow other related articles on the PHP Chinese website!