Home > Web Front-end > JS Tutorial > JavaScript Advanced Programming Reading Notes 11 Built-in Object Global_javascript Skills

JavaScript Advanced Programming Reading Notes 11 Built-in Object Global_javascript Skills

WBOY
Release: 2016-05-16 17:55:46
Original
983 people have browsed it
Built-in objects
Definition: All objects provided by the ECMAScript implementation that are independent of the host environment and appear when the ECMAScript program starts executing.

It can be seen from the definition that developers do not have to explicitly instantiate the built-in object, it has already been instantiated. Only two built-in objects are defined in ECMAScript-262, namely Global and Math

Global
The Global object is the most special object in ECMAScript, because in fact it does not exist at all.

Since there are no independent objects in ECMAScript, all functions must be methods of an object, such as the aforementioned isNaN(), isFinite(), parseInt() and parseFloat(), etc. Is a method of Global object.

Escape(), encodeURI(), encodeURIComponent(), unescape(), decodeURI(), decodeURIComponent(), eval(), etc. are all Global methods.

escape() && encodeURI() && encodeURIComponent()
 These methods are used to encode strings.

There are 69 unencoded characters in escape: *, , -, ., /, @, _, 0-9, a-z, A-Z

There are 82 unencoded characters in encodeURI: !, #,$,&,',(,),*, ,,,-,.,/,:,;,=,?,@,_,~,0-9,a-z,A-Z

encodeURIComponent does not encode 71 characters: !, ', (,), *, -, ., _, ~, 0-9, a-z, A-Z

 escape(): Not recommended, Deprecated

encodeURI(): Encode the URL, example:
Copy code The code is as follows :

encodeURI("http://www.jb51.net/a file with spaces.html")
// outputs http://www.jb51.net/a file with spaces.html

encodeURIComponent(): Encode parameters, example:
Copy code Code As follows:

param1 = encodeURIComponent("http://xyz.com/?a=12&b=55")
url ="http://domain.com/?param1=" param1 "¶m2=99";
// outputs http://www.domain.com/?param1=http://xyz.com/�a=12&b=55¶m2=99

unescape() && decodeURI() && decodeURIComponent()
 These methods are used to decode strings.

eval()
eval() may be the most powerful method in the ECMAScript language. This method is like the entire JavaScript interpreter, accepting one parameter, which is the function to be executed. ECMAScript (or JavaScript) string.

Example:

Copy code The code is as follows:

var msg="Hello world";
eval("alert(msg)");//alert "Hello world"

Note that the eval() function is very powerful, but it is also very dangerous. Especially when eval is used to execute user input, it may be injected by code.

All properties of Global object
Global not only has methods, it also has properties, all properties of Global object:

属性

说明

undefined

Undifined类型的字面量

NaN

非数的专用数值

Infinity

无穷大值的专用数值

Object

Object的构造函数

Array

Array 的构造函数

Function

Function 的构造函数

Boolean

Boolean 的构造函数

String

String 的构造函数

Number

Number 的构造函数

Date

Date 的构造函数

RegExp

RegExp 的构造函数

Error

Error 的构造函数

EvalError

EvalError 的构造函数

RangeError

RangeError 的构造函数

ReferenceError

ReferenceError 的构造函数

SyntaxError

SyntaxError 的构造函数

TypeError

TypeError 的构造函数

URIError

URIError 的构造函数

Author: Tian Xingjian, self-improvement

Source: http://artwl.cnblogs.com
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template