JavaScript Advanced Programming Reading notes Xi. built-in objects Global_javascript tips

Source: Internet
Author: User
Tags eval numeric value
Built-in objects
Definition: All objects provided by the ECMAScript implementation that are independent of the hosting environment appear when the ECMAScript program starts executing.

By definition, the developer does not have to explicitly instantiate the built-in object, it has been instantiated. Only two built-in objects are defined in ECMAScript-262, that is, global and math

Global
The global object is the most specific object in the ECMAScript because it does not actually exist at all.

Because there is no independent object in the ECMAScript, all functions must be methods of an object, such as the isNaN (), Isfinite (), parseint (), and parsefloat () mentioned earlier, are methods of the global object.

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

Escape () && encodeURI () && encodeuricomponent ()
These methods are used to encode strings.

Escape does not encode 69 characters: *,+,-,.,/,@,_,0-9,a-z,a-z

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

There are 71 encodeuricomponent characters that are not encoded:!, ', (,), *,-,.,_,~,0-9,a-z,a-z

   Escape (): not recommended, obsolete

encodeURI (): Encoding The URL, example:
Copy Code code as follows:

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

encodeURIComponent (): Encode parameters, Examples:
Copy Code code 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 () is probably the most powerful method in the ECMAScript language, which, like the entire JavaScript interpreter, takes a single parameter, the ECMAScript (or JavaScript) string to execute.

Example:

Copy Code code as follows:

var msg= "Hello World";
Eval ("Alert (msg)");//alert "Hello World"

Note that the Eval () feature is powerful, but also dangerous, and may be injected into the code, especially when you execute the content entered by the user with the eval.

all properties of the global object
Global is not only a method, it also has attributes, all properties of the global object:

Property

Description

Undefined

literal amount of undifined type

NaN

Private value for non-number

Infinity

Private numeric value for infinity

Object

constructor of Object

Array

the constructor of the Array

Function

constructor for function

Boolean

Boolean Constructor

String

the constructor for String

Number

the constructor for number

Date

the constructor for Date

Regexp

Constructor for RegExp

Error

the constructor of the Error

Evalerror

Constructor for Evalerror

Rangeerror

Constructor for Rangeerror

Referenceerror

Constructor for Referenceerror

SyntaxError

Constructor for SyntaxError

TypeError

Constructor for TypeError

Urierror

Constructor for Urierror

Author: Tian Xing Jian, 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.