How to export and import ES6 class in iojs?

312 Views Asked by At

In foo.js

class Foo {
    run(){
        console.log("test");
    }
}

In index.js

'use strict'    

var test = require('./foo.js'),
    Test = new test();

Test.run();

How to export the Foo class in iojs 3?

I tryed this way and worked, but i dont know if this is the right way:

module.exports = class Foo {
                    run(){
                        console.log("test");
                    }
                 }
1

There are 1 best solutions below

0
On

In current io.js you can do something like this to get your class exported so it can be imported with require():

'use strict'


class Foo {

}

module.exports = Foo;

and

const Foo = require('./foo');