08 ES.Next

Upcoming Features: ES-2019, Stage-3

  • Native Observables
  • Pipeline Operator
  • Logical Assignment Operators
  • Numerics
  • Arrays
  • Slice Notation
  • private class elements
  • ...

Native Observables


                    observable.observe(fnObserver)
  • Not yet available
  • Implemented by various frameworks (e.g RxJS)

Pipeline Operator "|>"


                    let result = null;

                    // pipelining functions (current solution)
                    result = doFn4(doFn3(doFn2(doFn1(string)));

                    // with pipline operator
                    result = string |> doFn1 |> doFn2 |> doFn3 |> doFn4;
                

Pipeline Operator for expressions, array functions, (async) function-calls

Pipeline Operator "|>"

  • Syntax gets slightly more cryptic
  • Better and more natural readability
  • Less repetition of common code patterns
  • More focus upon intention

Logical Assignment Operators


                    // or
                    a ||= b;
                    a || (a = b);

                    // and
                    a &&= b;
                    a && (a = b);
            

Inspired by Ruby. Works exactly as in Ruby

Logical Assignment Operators

  • Syntax gets slightly more cryptic
  • Less repetition of common code patterns
  • Less code

Slice Notation


                const arr = ['a', 'b', 'c', 'd'];

                console.log(arr[1:3] == arr.slice(1,3)); // ['b', 'c']
                console.log(arr[:2]  == arr.slice(0,2)); // ['a', 'b']
                console.log(arr[2:]  == arr.slice(2,4)); // ['c', 'd']
                console.log(arr[2:]  == arr.slice(2)); // ['c', 'd']

                console.log(arr[-1:] == arr.slice(3,4)); // ['d']
                console.log(arr[:-2] == arr.slice(0,3)); // ['a', 'b']
            

Slice Notation for arrays and objects

Inspired by Python. Works exactly as in Python

Slice Notation

  • Syntactic sugar to slice()
  • Increased clarity about start & end
  • More convenient and natural than function-call
  • Less repetition of common code patterns
  • Less code

Numerics: Groupings


                    const inhabitantsOfMunich = 1_464_301;
                    const distanceEarthSunInKm = 149_600_000;
                    const massOfElectronInKg = 9.109_383_56e-31;
                    const words = 0xFAB_F00D;

                    let result = Number.parseInt('123_345');
                    console.log(result == 123456);

                    let result = Number.parseFloat('0.123_456');
                    console.log(result == 0.123456);
                

identical specification & restrictions as in Java 8

Nummerics: BigInts


                    const massOfEarthInKg = 6_000_000_000_000_000_000_000_000n;

                    let bigInt = typeof 123n;
                    console.log(bigInt == 'bitInt');

                    let result = BigInt.parseInt('9007199254740993', 10);
                    console.log(result == 9007199254740993n);

                    console.log(0 == 0n); // false :(
                

identical usage as with any 'number'

Nummerics: Grouping & BigInts

  • better readability of large numbers
  • very large numbers
  • precision of very large fractions

BitInts will have a huge impact for money-related applications (financial technical sector)

Arrays: special elements (Stage-1)


                    let arr = [1, 2, 3, 4, 5, 6, 7];

                    console.log(arr.last == arr[arr.length - 1]);
                    console.log(arr.first == arr[0]);
                

Convenient access to special elements

Arrays: special elements (Stage-1)

  • Less repetition of common code patterns
  • Less code

Arrays: add/remove multiple elements (Stage-1)


                    // for loop
                    for (let item in items) {
                        arr.add(item);
                    }

                    arr.addAll(items);
                    arr.addAll(...items);
                    arr.addAll(item1, item2, ..., itemN);
                

Convenient add/remove of multiple elements

Arrays: add/remove multiple elements

  • Less repetition of common code patterns
  • Less code

private class elements


                    class SomeClass {
                        #xValue = 0; // private field
                        get #x() { return #xValue; } // private getter
                        set #x(value) { this.#xValue = value; } // private setter
                        #someMethod(args) { ... }; // private method
                    }

prefix any class element using '#' to make it private

private class elements

  • clean and stable interfaces
  • hidden changes under the hood

private methods & fields might have a huge impact

Other upcoming features ...

  • Dynamic (module) import
  • Moving away from global scope
  • Full Unicode Support in String & Regexp
  • Static class elements
  • ...

Resources

Can I use this?

Questions?