Reputation: 7337
Here is some class in class.js:
function Class(value1, value2) {
this.value1 = value1;
}
Class.prototype = {
value1: "default_value",
method: function(argument) {
this.value2 = argument + 100;
}
};
module.exports = exports = Class;
and here is a file in which I want to use this class:
var Class = require('../classes/class.js');
// (...)
var o = new Class(1,22);
What I get is an error:
TypeError: object is not a function
And indeed, Class
is {}
. I hoped this will help: Node.js object is not a function - module.exports, but I did everything like they said. What's wrong in my case?
Upvotes: 0
Views: 753
Reputation: 11389
module.exports = Class;
Should be all you need.
Note: your code works for me, though, so perhaps you are not requiring the right class.js
Upvotes: 2