Built-in object
Definition: all objects provided by ECMAScript and independent from the host environment are displayed when the ECMAScript program starts to run.
It can be seen from the definition that the developer does not need to explicitly instantiate the built-in object, and it has been instantiated. Only two built-in objects, Global and Math, are defined in the ECMAScript-262
Global
Global objects are the most special objects in ECMAScript, because they do not exist at all.
Because no independent object exists in ECMAScript, all functions must be methods of an object, such as isNaN (), isFinite (), parseInt (), and parseFloat, all are Global object methods.
Escape (), encodeURI (), encodeURIComponent (), unescape (), decodeURI (), decodeURIComponent (), and eval () are all Global methods.
Escape () & encodeURI () & encodeURIComponent ()
These methods are used to encode strings.
Escape unencoded characters are 69: *, +,-,.,/, @, _, 0-9, a-z, A-Z
EncodeURI is not encoded with 82 characters :!, #, $, &, ', (,), *, +,-,.,/,:,;, = ,?, @,_,~, 0-9, a-z, A-Z
EncodeURIComponent has 71 unencoded characters :!, ',(,),*,-,.,_,~, 0-9, a-z, A-Z
Escape (): not recommended, eliminated
EncodeURI (): encode the URL, for example:Copy codeThe Code is as follows: encodeURI ("http://www.jb51.net/a file with spaces.html ")
// Outputs http://www.jb51.net/a%20file%20with%20spaces.html
EncodeURIComponent (): encode the parameter, for example:Copy codeThe Code is as follows: param1 = encodeURIComponent ("http://xyz.com /? A = 12 & B = 55 ")
Url = "http://domain.com /? Param1 = "+ param1 +" & param2 = 99 ";
// Outputs http://www.domain.com /? Param1 = http % 3A % 2F % 2Fxyz.com % 2F % Ffa % 3D12% 26b % 3D55 & param2 = 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 an entire JavaScript interpreter that accepts a parameter, that is, the ECMAScript (or JavaScript) string to be executed.
Example:
Copy codeThe Code is as follows: var msg = "Hello world ";
Eval ("alert (msg)"); // alert "Hello world"
Note that eval () is powerful but dangerous, especially when using eval to execute user input content, it may be injected by code.
All attributes of the Global Object
Global does not only have methods, but also has all attributes of the Global object:
Attribute |
Description |
Undefined |
Undifined literal |
NaN |
Non-numeric value |
Infinity |
Special Value of an infinite value |
Object |
Object constructor |
Array |
Array Constructor |
Function |
Function Constructor |
Boolean |
Boolean Constructor |
String |
String Constructor |
Number |
Number Constructor |
Date |
Date Constructor |
RegExp |
RegExp Constructor |
Error |
Error Constructor |
EvalError |
EvalError Constructor |
RangeError |
RangeError Constructor |
ReferenceError |
ReferenceError Constructor |
SyntaxError |
Constructor of SyntaxError |
TypeError |
TypeError Constructor |
URIError |
URIError Constructor |
Author: tianxingjian, self-improvement
Source: http://artwl.cnblogs.com