ECMAScript 6 (Harmony) 新特性棒棒的!!!
发布于 1个月前 作者 jerrywu55 273 次浏览 来自 分享

Default parameters

    function multiply(a, b = 1) {
      return a*b;
    }
    
    multiply(5); // 5

Arrow functions

lambda 表达式

old

    function Person() {
      var self = this; // Some choose `that` instead of `self`. 
                       // Choose one and be consistent.
      self.age = 0;
    
      setInterval(function growUp() {
        // The callback refers to the `self` variable of which
        // the value is the expected object.
        self.age++;
      }, 1000);
    }

new

    function Person(){
      this.age = 0;
    
      setInterval(() => {
        this.age++; // |this| properly refers to the person object
      }, 1000);
    }
    
    var p = new Person();
回到顶部