0

Is there a difference between a constructor function vs a method like so:

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

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

I tried this on the babel REPL and tried to grok the code that it compiles but it doesn't make any sense to me ATM:

babelREPL

chrisjlee
  • 21,691
  • 27
  • 82
  • 112
  • `bar` is defined in `foo.prototype`. – Oriol Jul 17 '16 at 01:35
  • Had to answer, cause you didn't sure the ES5 example, so I am not sure if I should tell you that there is no difference or not, cause I can't compare this ES6 example to anything. BUT, I will say that ES6 classes are only capable of doing all the same things that Prototypes could do. – frosty Jul 17 '16 at 01:38

0 Answers0