JavaScript advanced programming book note 11 built-in object Global

Source: Internet
Author: User

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

UndifinedType literal

NaN

Non-numeric value

Infinity

Special Value of an infinite value

Object

ObjectConstructor

Array

ArrayConstructor

Function

FunctionConstructor

Boolean

BooleanConstructor

String

StringConstructor

Number

NumberConstructor

Date

DateConstructor

RegExp

RegExpConstructor

Error

ErrorConstructor

EvalError

EvalErrorConstructor

RangeError

RangeErrorConstructor

ReferenceError

ReferenceErrorConstructor

SyntaxError

SyntaxErrorConstructor

TypeError

TypeErrorConstructor

URIError

URIErrorConstructor

Author: tianxingjian, self-improvement

Source: http://artwl.cnblogs.com

Related Article

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.