ECMAScript 2018 Is Feature Complete |
Written by Ian Elliot | |||
Monday, 05 February 2018 | |||
What's new in JavaScript/ES2018? Not much, but keep your eye on what is happening or it might just come as a surprise. Although the new TC39 process, which pushes new JavaScript features through the approvals mill one at a time, makes the yearly release less important it still produces a bundle of changes that we can discuss. Yes it's ES2018 already. Not a great deal, and this is a good, not bad, thing. JavaScript should be a mature language by now and after the huge changes in ES2015 we need some stability. Probably the most important of the new features is Asynchronous iteration. Synchronous iteration, introduced in ES2015, lets you write:
The new feature extends this to long running asynchronous operations using await:
which doesn't block the UI thread while waiting for the asynchronous iterator. You can, of course, create your own asynchronous iterables. The only problem is that the feature isn't widely supported as yet, but all of the JavaScript engines are being updated to include it. The next biggest feature is probably the rest spread operator and you might be forgiven for thinking that this was already in JavaScript. The rest operator works in ES2015 on arrays and now in ES2018 on objects. If you destructure an object you can now add ... to signal that any remaining properties should be packed into the final variable. For example:
stores 1 in x, 2 in y and {a:3,b:4} in z i.e. the rest of the object. Similarly the spread operator now works in objects:
gets us back to our original object {x:1,y:2,a:3,b:4} We also have some new features in regular expressions: named capture groups, unicode property escapes, lookbehind assertions and s(dotAll) flag. JavaScript has had numbered groups for a while, but now you can assign an id and use that id in a backreference etc. Unicode property escapes extend the classification of characters to unicode properties such as Greek characters,Currency_Symbol and so on. Lookbehind assertions are a generalization of lookahead assertions and are likely to make regular expressions even harder to understand! Finally we have finally. Well Promise.finally to be exact. As we reported on the release of Firefox 58, you can now use the Promise finally method to run code no matter how the Promise resolves. What can we expect for ES2019? Of the proposals close to being completed, the idea of adding 64-bit integers is likely to be the most useful. If you want to use JavaScript like a class-based language then you might also like public and private fields - just add a # to the front of a property name and it becomes private. It may be backward compatible, but it introduces the sigil into JavaScript and should be resisted for this reason alone.
More Informationhttps://github.com/tc39/proposals Related ArticlesFirefox 58 - Tab Throttling, WebAssembly, Promise Finally And Progressive Web Apps JavaScript The Language With Two Names The JavaScript Encyclopedia Work In Progress JavaScript Added To Oxford English Dictionary JavaScript 6 EcmaScript 2015 Final Approval To be informed about new articles on I Programmer, sign up for our weekly newsletter, subscribe to the RSS feed and follow us on Twitter, Facebook or Linkedin.
Comments
or email your comment to: comments@i-programmer.info
|
|||
Last Updated ( Friday, 15 June 2018 ) |