神刀安全网

New JavaScript: ES7 and beyond

The draft ECMAScript 2016 standard is online here and it contains two new features:

  • Array.prototype.includes
  • Exponentiation operator

So let’s take a look at the new features

Array.prototype.includes

This is a new method for arrays to check if an array contains a value. It works pretty much as you’d expect.

[1, 2, 3, 4].includes(4);       // true [1, 2, 3, 4].includes(5);       // false 

It’s almost the same as using

[1, 2, 3, 4].indexOf(4) >= 0;   // true 

The difference is that it will find NaN

[NaN].includes(NaN);           // true [NaN].indexOf(NaN) >= 0;       // false 

According to this compatability table it looks like it’s already surprisingly well supported.

The usual suspects are lagging behind but if you’re on an up to date Edge, Chrome or Firefox you should be able to pop open the console and try it out.

Exponentiation operator

The exponentiation operator is a new operator for using exponentials.

2 ** 3;                       // 8   3 ** 3;                       // 27   

It’s almost the same as

Math.pow(2, 3);               // 8   

Except that because it’s an operator you can do things like this

var a = 3;   a **= 3;                      // 27   

If you’d like to start using it in the browser, you’re probably going to have to wait. Pretty much no-one except Edge or Chrome Canary has implemented it yet.

If you want to use it in your next project, babel has a plugin for transpiling it here .

Why so small?

At first glance ES7 isn’t too exciting. It’s a pretty small release with just 2 vanilla features.

But the exciting thing about ES7 isn’t what is in it, it’s exciting that it exists at all. This small release proves that then new JavaScript release process is working.

ES6 was a nightmare to get ratified and approved because there were so many changes.

So going forward Technical Committee 39 (TC39) is maintaining a backlog of new language features and doing smaller incremental releases of whichever features are ready. The fact that ES7 is so small proves that TC39 is making more frequent, smaller releases. So now the developer community can get their hands on new features earlier.

How TC39 works

They meet every 2 months and their meeting notes can be found online here . Their meetings look pretty much like you’d imagine. Here’s a picture from last year. You could probably use it as a stock image for ‘Technical Committee’.

New JavaScript: ES7 and beyond

You can find the feature backlog [here] ( https://github.com/tc39/ecma262/blob/master/README.md )

Each feature is classified into stages base on it’s maturity:

  • Stage 1 – Proposal
  • Stage 2 – Draft
  • Stage 3 – Candidate
  • Stage 4 – Finished

And beyond

The great thing about this new process is that it makes the upcoming features visible. If you look at the list of current proposals you can see that the Stage 3 features are the most likely to make it into ES8.

The language feature that I’m the most excited about is the Async stuff which will help improve the language level model for writing asynchronous code.

References

I’d like to throw out a special thank you to Dr Alex Rauschmayer for his wonder blog @ality . It’s what sparked my interest in how JavaScript is made and what’s coming up in ES7 and beyond.

转载本站任何文章请注明:转载至神刀安全网,谢谢神刀安全网 » New JavaScript: ES7 and beyond

分享到:更多 ()

评论 抢沙发

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址