I am trying my might at doing a NODE JS project, and learning the in's and outs of the Node JS structure. I have looked all over the internet to find out how to do this with little or no luck. The problem is as follows:
I have a class called player, which was created in a file called player.js
var playa = function ()
{
this.createPlayer = function(){
}
}
In my index.js file I link my player
var playa = require("./player.js");
however, when I try to reference my player
io.on('connection', function(socket){
var player = new playa();
player.createPlayer();
});
the console tells me that playa is not a function and the server stops.
- Am I even allowed to use traditional OOP JS in node? If I move this class to the index.js file it works splendidly, however it will get sloppy since the class is large and I plan on using at least 5 classes.
2.If it is possible too structure my objects this way, how do I link them/reference them correctly?
- if neither or possible, what would be the correct way to structure my objects? I am hoping not to get away from my current convention since that is what I am used to and I need to create multiple instances of player.
undefinedas a default value) from yourplayer.jsmodule. Hence the error.