user2920222
user2920222

Reputation: 197

Node.js module.exports multiple classes

I have 2 files called a.js and b.js, both contain classes. I'm trying to import and create a new instance of class B inside class A using the following code

a.js

module.exports.A = A;
var classB = require('./b.js').B;
A.protoype.Init = function(){
this.B = new classB();

b.js

module.exports.B = B;
function B(a_class)
{
  this.a = a_class;
}

I receive the following error

TypeError: undefined is not a function at this.B = new class B();

Upvotes: 2

Views: 2310

Answers (1)

officert
officert

Reputation: 1232

You haven't defined your A class in your a.js file:

a.js - I added a constructor function for your A class:

module.exports.A = A;
var classB = require('./b.js').B;

function A() {}

A.protoype.Init = function(){
    this.B = new classB();
}

Upvotes: 1

Related Questions