How do I perform an export that is compatible with ES5 and ES6?

后端 未结 3 972
傲寒
傲寒 2021-02-02 07:36

I\'m writing a \"class\" in node

// mymodule/index.js

function MyClass() {}
MyClass.prototype.method1 = function() {..}

usually I do

3条回答
  •  余生分开走
    2021-02-02 08:31

    From the comments, I understand you are trying to run your ES6 frontend code in some mocha unit tests in node. Yes, you can't do that until node support ES6 modules. If I were you, I would use systemjs to load code for those mocha tests. Mocha supports promises, so it should be fairly painless to load any files before tests.

    Writing syntax for both will just create more problems for you.

提交回复
热议问题