I am trying to develop a factory that will generate a PlayerList, but I am encountering issues with accessing the variables I have defined in the initialize function. Below is the code snippet:
app.factory("PlayerList", function(){
// Define the PlayerList function
var PlayerList = function() {
this.initialize = function() {
// create an array for our players
var players = [];
};
this.add = function(player) {
this.players.push(player);
}
this.remove = function(player) {
if ( players.length > 0 )
{
this.players.splice(players.indexOf(player), 1);
}
}
this.initialize();
};
return (PlayerList);
});
I am aiming to access the players array within the add and remove methods, however, I keep receiving undefined as the output.