I have a bit complicated JS Objects structure:
var Players = {};
Players.Player = function (color) {
this.color = color; //the color can be either black or white
Players[color] = this;
}
Players.Player.prototpe.Piece = function () {
return this.parent.color //of course, this is not valid
}
new Players.Player("black");
new Players.Player("white");
new Players["black"].Piece(); //here I want to get "black"
new Players["white"].Piece(); //here I want to get "white"
I hope I described my problem well enough. I want to be able to return the color of the paret of the constructor, meaning to replace this.parent.color
with a better command that will return "black" on the first piece and "white" on the second piece.
Thank you!