I think I'm probably doing something silly, but I'm not sure...
I have these two classes:
function Sprite()
{
}
Sprite.prototype.test1 = function()
{
console.log("test1");
}
function Player()
{
}
Player.prototype.test2 = function()
{
console.log("test2");
}
Player.prototype = new Sprite();
var player = new Player();
player.test1(); // this works
player.test2(); // this doesn't work..
I'm struggling to understand why test2() doesn't work, but test1() does work. If I add properties to these classes then I can access properties from both of them, I just can't call methods from the player class. What am I doing wrong?
Player.prototype.test2when you assign a whole object toPlayer.prototype. If you definedtest2after, it would create the method on the new object instead, and both would work.