Let's say we have two such constructors:
function Player(x, y) {
this.x = x;
this.y = y;
this.hello = function() {
console.log("Hello, " + this.npc);
}
}
function World() {
this.player = new Player(0, 0);
this.npc = "villager";
}
How can I access the npc property for World from the hello function in Player?
this one does not work since World is not a prototype Player.
source
share