JavaScript Advanced Programming (3rd Edition) learning notes ECMAScript5 new Features _ Basics

Source: Internet
Author: User
Tags eval reserved
Then there should be BOM and HTML5, but given the new changes in ECMAScript5 relative to ECMASCRIPT3, and these changes are also very interesting, so in this article I think of the interesting changes (not all changes) to focus on, but here is just the list , not specifically unfolded.

I. Grammatical changes

1, keywords and reserved words

In ES3, using a keyword to do an identifier causes a "Identifier expected" error, and using a reserved word identifier may or may not cause the same error, depending on the particular engine. In ES5, keywords and reserved words cannot be used as identifiers, but they can be the property names of objects. Let and yield are added to the keywords and reserved words in ES5. To ensure maximum compatibility, do not use as identifiers either ES3 or ES5 keywords and reserved words.

2, Property characteristics

ES5 allows you to override properties such as enumerable, configurable, writable, get, set, and so on for a given property using a user-defined attribute description. The way to do this is to use a static function that is defined on object objects.

3. Strict mode

The biggest grammatical change is the introduction of strict mode, which can be "use strict" by the statement; To turn on strict mode, add the entire script at the top of the code to enable strict mode, and within the function, only strict mode is enabled for the function. The major changes in the strict mode are:

(1) A variable must be defined before it is used, that is, implicit global variables are not allowed

(2) Do not use octal data

(3) Do not use the WITH statement

(4) Eval

A, you cannot use eval as an identifier, so you cannot name a variable or function as Eval

B, external cannot access variables defined in the eval () function

(5) Arguments

A, you cannot use arguments as an identifier

B, can not modify the arguments as the internal object of the function, so there is no synchronization between the formal parameter and the arguments

C, unable to access Arguments.callee

D, ES5 defines the Arguments.caller property, its value is always undefined, mainly used to distinguish arguments.caller and function caller, but not in strict mode access

(6) function

A, there cannot be two formal arguments with the same name in a function

B, cannot assign value to the function's caller property

C, do not specify the environment object and call the function, this value does not point to window, but undefined

(7) Object

A, two properties with the same name cannot appear in an object

B, when modifying an attribute [[writable]] to False, an exception is thrown instead of silently, and an exception is thrown when a property with the delete attribute [[[configurable]] false is used.

(8) Delete

You cannot delete variables and functions that display declarations by using delete

Ii. changes in the built-in objects

1, Object objects

(1) Inheritance related methods: Create (), getprototypeof ()

(2) Property related methods: DefineProperty (), Defineproperties (), Getownpropertydescriptor (), Getownpropertynames (), Keys ()

(3) Tamper-Proofing methods: Preventextensions (), isextensible (), Seal (), issealed (), Freeze (), IsFrozen ()

2. Function Object

(1) The Bind () method is added.

(2) A property caller of a function object is normalized for reference to a function that invokes the current function.

(3) prototype is not enumerable

3, Array Object

(1) Method of judgment: Added static method Array.isarray (obj) to determine whether obj is an instance of an array object.

(2) Indexing method: Two methods indexof () and LastIndexOf () were added to find the specified item index. The lookup uses strict equality (= = =) to match.

(3) Iterative method: Added every (), some (), ForEach (), map (), filter () method.

(4) Narrowing method: Add the reduce () and Reduceright () method.

4, String Object

The trim () method was added.

5. JSON Object

Added native JSON built-in object.

6. Date Object

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

7, RegExp Object

In ES3, you share a regexp instance when you use regular expression literals, and in ES5, you create a new RegExp instance every time you use regular expression literals, just as you would with a regexp constructor.
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.