ES.Next features review (es7|es8|es9)

Novikov Kirill

ES.Next features review

es7 | es8 | es9

Brought to you by Kirill Novikov

What is ECMA, ECMAScript, ECMA-262, TC-39

European Computer Manufacturers Association (ECMA)

https://en.wikipedia.org/wiki/List_of_Ecma_standards

ECMAScript (ECMA-262)

https://en.wikipedia.org/wiki/ECMAScript

ECMAScript releases before 2017
ECMAScript implementations

TC39 (Technical Committee 39)

ECMAScript 2016

Array.prototype.includes

Signature:

			Array.prototype.includes(value : any) : boolean
		

Example:

			['a', 'b', 'c'].includes('a')
		
			> true
		

Exponentiation operator (**)

Example:

			6 ** 2
		
			> 36
		

The same

			Math.pow(6, 2)
		

ECMAScript 2017

Async functions

Object.entries

Signature:

			Object.entries(value : any) : Array<[string,any]>
		

Example:

			let obj = { one: 1, two: 2 };
			for (let [k,v] of Object.entries(obj)) {
			    console.log(`${k}: ${v}`);
			}
		

Object.values

Signature:

			Object.values(value : any) : Array<any>
		

Example:

			Object.values({ one: 1, two: 2 })
		
			> [ 1, 2 ]
		

padStart and padEnd

Example:

			'x'.padStart(5, 'ab')
		
			> 'ababx'
		
			'x'.padEnd(5, 'ab')
		
			> 'xabab'
		

Object.getOwnPropertyDescriptors

			const obj = { get es8() { return 888; } };
			Object.getOwnPropertyDescriptor(obj, 'es8');
		

Output:

			{
		
			  configurable: true,
		
			  enumerable: true,
		
			  get: function es8(){}
		
			  set: undefined
		
			}
		

ECMAScript 2018

Asynchronous iteration

			const promises = [
			  new Promise(resolve => resolve(1)),
			  new Promise(resolve => resolve(2)),
			]
			for await (const obj of promises) {
			  console.log(obj)
			}
		

Output:

			> 1, 2
		

Spread properties for Objects

			const obj = {foo: 1, bar: 2, baz: 3};
			const {foo, ...rest} = obj;
		

Output:

			> foo: 1
		
			> rest: {bar: 2, baz: 3}
		

Promise.prototype.finally()

			promise
			.then(result => {···})
			.catch(error => {···})
			.finally(() => {···});
		

RegExp named capture groups

			const RE_DATE = /(?<year>[0-9]{4})-(?<month>[0-9]{2})-(?<day>[0-9]{2})/
			const matchObj = RE_DATE.exec('1999-12-31');
			const year = matchObj.groups.year; // 1999
			const month = matchObj.groups.month; // 12
			const day = matchObj.groups.day; // 31
		

RegExp lookbehind assertions

			const RE_DOLLAR_PREFIX = /(?<=\$)foo/g;
			'$foo %foo foo'.replace(RE_DOLLAR_PREFIX, 'bar');
		

Output:

			> '$bar %foo foo'
		

И еще

Полезные ссылки