Undefined Behavior
Undefined Behavior

Reputation: 2208

How to export and import ES6 class in iojs?

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");
                    }
                 }

Upvotes: 0

Views: 297

Answers (1)

recidive
recidive

Reputation: 388

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');

Upvotes: 0

Related Questions