Reputation: 825
In my main.js
, I have:
var example = require('./test');
example.speak('Hello world');
While in my test.js
, I have:
module.exports = function() {
this.speak = function(str) {
str += ' < you typed.';
return str;
};
this.listen = function(str) {
return str;
};
};
What exactly am I doing wrong so that I can use browserify
correctly with this?
Upvotes: 0
Views: 47
Reputation: 11171
You should either export an object:
module.exports = {
speak: function () {},
// etc
}
or use
var example = new require("./test")();
Upvotes: 1