The latest ECMAScript standard defines seven data types:

Six data types that are primitives:
    Boolean
    Null
    Undefined
    Number
    String
    Symbol (new in ECMAScript 6)
and Object

Symbol: is a class like function which will return an unique symbol instance, even if the name is same, so we can use it as the private key of an object or calss, to make this property private and use internally, because it's non-enumerable, will not show in for in loop, you can get it from using the symbol instance or using Object.getOwnPropertySymbols()

note:

  1. cannot use 'dot' to operate the Symbol property on an object
  2. when defining Symbol in an object literal, need to use '[ ]' to wrap the Symbol key

Generator:

function* f(){

yield 'hello';

tield: 1+1;

return 'ending'

}

let ff = f();

ff.next(); //{value: 'hello', done:false}

ff.next();//{value:2, done:false}

ff.next();//{value:'ending', done:true}

yield: the value is executed when the 'pointer' points here, 'lazy-evaluation'

compared to return statement, which can only be executed once, yield can be executed multi times.


Inheritance:

  • ES 6 use class inheritance 'extends' to do the inheritance, and ES5 use the prototype chain to do the inheritance.

  • unlike the ES5 which create the child instance 'this' first, and then apply parent methods to child 'this'. In ES6 the parent class create the 'this' first, and then use the child constructor function to modify the 'this' object, that's why we need to call 'super()' in the children constructor, otherwise it will have error. and also you cannot use 'this' before calling 'super()' in constructor.

  • 'this' in super is the child instance, so calling super() in child is like calling 'Parent.prototype.constructor.call(this)'

results matching ""

    No results matching ""