JavaScript advanced programming (version 3rd) learning notes 13 new features of ECMAScript5

Source: Internet
Author: User

The next step is BOM and HTML5, but since ECMAScript5 has many new changes compared with ECMAScript3, these changes are also very interesting, therefore, in this article, I will focus on the interesting changes I think (not all changes), but here I will only list them, not specifically.

I. Syntax changes

1. keywords and reserved words

In ES3, using keywords for Identifiers leads to the "Identifier Expected" error. Using reserved words for identifiers may not cause the same error, depending on the specific engine. In ES5, keywords and reserved words cannot be used as identifiers, but can be used as attribute names of objects. In ES5, let and yield are added to the keywords and reserved words. To ensure maximum compatibility, do not use keywords or reserved words in ES3 or ES5 as identifiers.

2. Attribute features

ES5 allows you to use User-Defined attribute descriptions to overwrite enumerable, retriable, writable, get, set, and other attributes of a given attribute. The specific method is to use static functions defined on the Object.

3. Strict Mode

The biggest syntax change is the strict mode. You can use the statement "use strict"; to enable the strict mode, and add the entire script to the top of the Code to enable the strict mode, add a function to enable strict mode only for the function. Major changes in strict mode include:

(1) variables must be defined first, that is, implicit global variables are not allowed.

(2) do not use gossip data

(3) do not use the with statement

(4) eval

A. You cannot use eval as an identifier. Therefore, you cannot name variables or functions as eval.

B. variables defined in the eval () function cannot be accessed externally.

(5) arguments

A. arguments cannot be used as the identifier.

B. You cannot modify the arguments used as the internal object of the function. Therefore, the formal parameters and arguments do not change synchronously.

C. Cannot access arguments. callee

D. ES5 defines the arguments. caller attribute. Its value is always undefined, which is mainly used to distinguish arguments. caller from the caller of the function, but cannot be accessed in strict mode.

(6) Functions

A. Two formal parameters with the same name cannot appear in the function

B. The caller attribute of the function cannot be assigned a value.

C. Call a function without specifying an environment object. The value of this is undefined instead of a window.

(7) object

A. Two attributes with the same name cannot appear in the object.

B. If you modify an attribute whose [[writable] is false, an exception is thrown instead of silent failure, an exception is thrown when the delete attribute [[resumable] is set to false.

(8) delete

You cannot use delete to delete declared variables and functions.

2. Changes to built-in objects

1. Object

(1) Inheritance related methods: create (), getPrototypeOf ()

(2) attributes related methods: defineProperty (), defineProperties (), getOwnPropertyDescriptor (), getOwnPropertyNames (), keys ()

(3) Tamper-proofing methods: preventExtensions (), isExtensible (), seal (), isSealed (), freeze (), isFrozen ()

2. Function object

(1) added the bind () method.

(2) Normalize the caller attribute of a function object to point to the reference of the function that calls the current function.

(3) prototype cannot be enumerated.

3. Array object

(1) Judgment Method: The static method Array. isArray (obj) is added to determine whether obj is an Array object instance.

(2) indexing method: added two methods indexOf () and lastIndexOf () for searching the specified index (). Use full equal (=) for matching during search.

(3) iterative method: The methods every (), some (), forEach (), map (), and filter () are added.

(4) reduce method: The reduce () and reduceRight () methods are added.

4. String object

Added the trim () method.

5. JSON object

Added built-in native JSON objects.

6. Date object

Added methods such as Date. now () and Date. prototype. toJSON.

7. RegExp object

In ES3, A RegExp instance is shared when the regular expression is used to literally, and in ES5, a new RegExp instance is created each time the regular expression is used to literally, just like using RegExp constructor.

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.