Let's say we have two constructors like these:
function Player(x, y) {
this.x = x;
this.y = y;
this.hello = function() {
console.log("Hello, " + this.npc); // World npc property
}
}
function World() {
this.player = new Player(0, 0);
this.npc = "villager";
}
How can i access the npc property of World from the hello function in Player?
this doesn't work, since World is not a prototype of Player.
hellowho it's greeting. Pass it in as a param.