<exploring ES6> 读书笔记 - Core ES6 features

  1. From var to const/let;
  2. From IIFEs(Immediately-Invoked Function Expression) to blocks;
  3. From concatenating strings to template literals -> ``;
  4. From function expressions to arrow functions, array function没有this;
  5. Handling multiple return values
    --Multiple return values via arrays //const [, year, month, day] = [0, 2012, 2, 2]
    --Multiple return values via objects //const {foo, bar} = {'foo':'full', 'bar':3, 'name':'eric'}
  6. From for and forEach() to for-of;
  7. Handling parameter default values -> function foo(x=0, y=0) {};
  8. From arguments to rest parameters (变长参数) foo(...args);
  9. 通过spread operator (...) 去把Array 变成非数组序列;
  10. From function expressions in object literals to method definitions;

    var obj = {

     foo: function () {
         ···
     },
     bar: function () {
         this.foo();
     }, // trailing comma is legal in ES5

    }

to

const obj = {
    foo() {
        ···
    },
    bar() {
        this.foo();
    },
}
  1. 使用 class 和 extend 定义类和继承关系

    class Employee extends Person {}

  2. From custom error constructors to subclasses of Error

    class MyError extends Error {}

  3. From objects to Maps;
  4. String 和 Array 新方法;

标签: none

添加新评论