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

后端 未结 3 969
傲寒
傲寒 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:08

    Both ways are correct, but try to import in es6 like this without the brackets:

    import MyClass from 'mymodule'
    

    Otherwise you would have to export your function like this:

    module.exports.MyClass = MyClass
    

    and than import it like this:

    import { MyClass } from 'mymodule'
    

提交回复
热议问题