Say I have two constructors for class Entity, and Player. (Player is intended to inherit from Entity)
var Entity = function(speed) { this.speed = speed; }
var Player = function(name) { Entity.call(this, 10); this.name = name; }
assert(new Player('p1') instanceof Entity === false)
In order for new Player objects to be an instanceof Entity, I would usually do something like...
Player.prototype = new Entity();
But this adds a useless object to the Player prototype chain which i will never use because I don't want players to share a single 'speed' variable. It may be unique for each player.
Player.prototype = Entity.prototype
doesn't work either since Entity objects also become instanceof Player
...
Is there a way I can simulate inheritance, just to get instanceof to work, without introducing useless objects in the prototype chain?