Introduction to the

Since THE release of ES6 (ECMAScript 2015) in 2015, ECMAScript has continued to evolve at the rate of one release per year. Now it’s ECMAScript 2020.

Each release comes with some new features, and today’s article will cover the new features introduced in ES7.

TC39 and ECMAScript

A history of ECMA. ECMA was established on April 27, 1960 as a manufacturer’s association with the purpose of harmonizing standards and making them portable across manufacturers. The Association was named the European Computer Manufacturers Association, or ECMA.

In 1994, to reflect the global activities of THE ECMA association, it was renamed the European Association for Information and Communication Systems. Although it retains the name European, it is already an international association.

Let’s take a look at the Members of THE ECMA Association. The most senior Members are called Ordinary Members, and they are basically international corporations:

And then the next level is called Associate Members:

You can see that there are several Chinese companies in it, which shows that China already has a say in the rule-making of the world.

TC39 is a committee of the ECMA Association that specifies ECMAScript standards. TC means Technical Committees.

There are many TCS under ECMA, and TC39 is specifically responsible for the development of ECMAScript.

TC39 is divided into two Task groups below. Respectively is:

  • Tc39-tg1 — General ECMAScript® Language is responsible for the development of ECMAScript
  • Tc39-tg2 — ECMAScript® Internationalization API Specification Is responsible for the establishment of the ECMAScript Internationalization API

We know that ES5 was written in 2009, and ECMAScript 2015 (ES6) was written in 2015, because ES6 includes 6 years of changes, so the changes to ES6 are quite big.

Since ES6, the ECMA Association has decided to release a version of ECMA every year, in order to reduce the pressure on vendors to adapt their ECMA scripts.

Here’s how ECMAScript is published. The release of ECMAScript is divided into the following five phases:

  • Stage 0: strawman

This is the free commit phase, but the contributor must be a TC39 member or TC39 contributor.

  • Stage 1: proposal

After the strawman of Stage 0 is reviewed by TC39, it goes to the proposal Stage.

At this stage it is necessary to know who is responsible for the proposal, and to submit the proposal examples, APIS, and semantic and algorithmic implementations. You also need to identify possible conflicts between this proposal and existing functionality.

If this proposal is accepted by TC39. So TC39 will continue to follow up this proposal.

  • Stage 2: draft

This is the first version of the proposal, which must also have a formal description (using the formal language of the ECMAScript specification) of the syntax and semantics of the functionality. Description needs should be as complete as possible, but can include to-do items and placeholders.

  • Stage 3: candidate

Most of the proposals at this stage have been completed, and further adjustments need to be made according to users’ feedback.

  • Stage 4: finished

The proposal at this stage is ready to be included in the next version of ECMAScript.

New features in ECMAScript 2016(ES7)

In fact, ECMAScript 2016(ES7) only has two new features:

  • Array.prototype.includes
  • Exponentiation operator (**)

Array’s new method includes

ES7 adds a new method to Array including. Let’s take a look at an example:

> ['a'.'b'.'c'].includes('a')
true
> ['a'.'b'.'c'].includes('d')
false
Copy the code

Take a look at the definition of includes:

Array.prototype.includes(value : any) : boolean
Copy the code

Returns true if value is included in Array, false if not.

As you can see, includes and indexOf are similar:

arr.includes(x)
Copy the code

Is equivalent to:

arr.indexOf(x) >= 0
Copy the code

The difference is that includes can look for NaN, while indexOf cannot:

> [NaN].includes(NaN)
true
> [NaN].indexOf(NaN)
-1
Copy the code

Include does not distinguish between +0 and -0:

> [-0].includes(+0)
true
Copy the code

She Typed Array. She Typed Array.

  • Int8Array
  • Uint8Array
  • Uint8ClampedArray
  • Int16Array
  • Uint16Array
  • Int32Array
  • Uint32Array
  • Float32Array
  • Float64Array
  • BigInt64Array
  • BigUint64Array

So the includes method also works with TypedArray:

let tarr = Uint8Array.of(12.5.3);
console.log(tarr.includes(5)); // true
Copy the code

The power operator **

ES7 introduces the power operator ** :

> 6 ** 2
36
Copy the code

The above example represents 6 to the second power.

The value of x ** y is equivalent to math.pow (x, y).

Let’s look at the basic use of the power operator:

const squared = 3 ** 2; / / 9

let num = 3;
num **= 2;
console.log(num); / / 9

function dist(x, y) {
  return Math.sqrt(x**2 + y**2);
}
Copy the code

The power operators have very high precedence, ** > * > +

> 2**2 * 2
8
> 2* * (2*2)
16
Copy the code

conclusion

There are only two new ES7 features, which are relatively simple and will be covered here today.

Author: Flydean program stuff

This paper links: www.flydean.com/ecmascript-…

Source: Flydean’s blog

Welcome to pay attention to my public number: “procedures those things” the most popular interpretation, the most profound dry goods, the most concise tutorial, many you do not know the small skills you find!