I'm confused with javascript modules and classes. I'm trying to create an object of my class, but it always says "cannot set property of undefined" or "object has no method". There is my module 2.js:
(function() {
var Game = function() {
this.state = 'a';
};
Game.prototype.somefunc = function() {
console.log(this.state);
};
})();
This is the main app code:
var g = require('./2.js');
var mygame = new g.Game;
mygame.somefunc();
//undefined is not a function error
or
var g = require('./2.js');
var mygame = g.Game;
mygame.somefunc();
//cannot call method of undefined error
What am I doing wrong?