ES 2018

padding

str.padStart(targetLength [, padString])
str.padEnd(targetLength [, padString])
'es8'.padStart(2);          // 'es8'
'es8'.padStart(5);          // '  es8'
'es8'.padStart(6, 'woof');  // 'wooes8'
'es8'.padStart(14, 'wow');  // 'wowwowwowwoes8'
'es8'.padStart(7, '0');     // '0000es8'
'es8'.padEnd(2);          // 'es8'
'es8'.padEnd(5);          // 'es8  '
'es8'.padEnd(6, 'woof');  // 'es8woo'
'es8'.padEnd(14, 'wow');  // 'es8wowwowwowwo'
'es8'.padEnd(7, '6');     // 'es86666'

Object.values

Object.keys vs for...in

const obj = { x: 'xxx', y: 1 };
Object.values(obj); // ['xxx', 1]

const obj = ['e', 's', '8']; // same as { 0: 'e', 1: 's', 2: '8' };
Object.values(obj); // ['e', 's', '8']

const obj = { 10: 'xxx', 1: 'yyy', 3: 'zzz' };
Object.values(obj); // ['yyy', 'zzz', 'xxx']
Object.values('es8'); // ['e', 's', '8']
const obj = { x: 'xxx', y: 1 };
Object.entries(obj); // [['x', 'xxx'], ['y', 1]]

const obj = ['e', 's', '8'];
Object.entries(obj); // [['0', 'e'], ['1', 's'], ['2', '8']]

const obj = { 10: 'xxx', 1: 'yyy', 3: 'zzz' };
Object.entries(obj); // [['1', 'yyy'], ['3', 'zzz'], ['10': 'xxx']]
Object.entries('es8'); // [['0', 'e'], ['1', 's'], ['2', '8']]

getOwnPropertyDescriptors

const obj = { get es8() { return 888; } };
Object.getOwnPropertyDescriptor(obj, 'es8');
// {
//   configurable: true,
//   enumerable: true,
//   get: function es8(){}, // функция геттер
//   set: undefined
// }

Trailing comma

function es8(var1, var2, var3,) {
  // ...
}
function fetchTextByPromise() {
  return new Promise(resolve => { 
    setTimeout(() => { 
      resolve("es8");
    }, 2000);
  });
}
async function sayHello() { 
  const externalFetchedText = await fetchTextByPromise();
  console.log(`Hello, ${externalFetchedText}`); // Hello, es8
}
sayHello();
var async = (generator: (imgs: string) => IterableIterator<Promise<HTMLImageElement>>) => {
    return (...rest) => {
        var iterator = generator.apply(null, rest),
            wait = (result: IteratorResult<Promise<HTMLImageElement>>) => {
                if (result.done) {
                    return result.value;
                } 

                result.value.then(image => {
                    wait(iterator.next(image));
                }, error => {
                    iterator.throw(error);
                });
            }
        
        wait(iterator.next());
    };
}

Atomics 

Atomics 

  • add
  • sub
  • load
  • and
  • or
  • xor
  • store
  • exchange
  • compareExchange
var sab = new SharedArrayBuffer(1024);
var ta = new Uint8Array(sab);

Atomics.add(ta, 0, 12); // returns 0, the old value
Atomics.load(ta, 0); // 12

Wait

  • wait
  • wake
  • isLockFree
Atomics.wait(typedArray, index, value[, timeout])
var sab = new SharedArrayBuffer(1024);
var int32 = new Int32Array(sab);
Atomics.wait(int32, 0, 0);
console.log(int32[0]); // 123
console.log(int32[0]); // 0;
Atomics.store(int32, 0, 123); 
Atomics.wake(int32, 0, 1);
Atomics.wake(typedArray, index, count)
Atomics.isLockFree(1); // true
Atomics.isLockFree(2); // true
Atomics.isLockFree(3); // false
Atomics.isLockFree(4); // true
Atomics.isLockFree(5); // false
Atomics.isLockFree(6); // false
Atomics.isLockFree(7); // false
Atomics.isLockFree(8); // false

Future

ES 2018

By Vladimir

ES 2018

  • 63