ES6类构造函数和方法之间有什么区别吗?

时间:2016-07-17 01:30:38

标签: javascript ecmascript-6 babeljs

构造函数与这样的方法之间是否存在差异:

class foo {
  constructor() {
    // A -> Function inside constructor
    this.init = () => {
      console.log('test');
    }
  }

  // B -> Method
  bar() {
    console.log('foo');
  }
}

我在babel REPL上试过这个并试图弄清楚它编译的代码,但它对我来说没有任何意义:

babelREPL

0 个答案:

没有答案