The standard way to call the constructor of a superclass is to use Function.call :
function Moveable(x, y) { Sprite.call(this, x, y); }
As for the prototype, you can do something like this to bind the prototype without creating an instance of the superclass:
function makePrototype(superclass) { function f() { } f.prototype = superclass.prototype; return new f(); } Moveable.prototype = makePrototype(Sprite);
To create an object that has the same prototype as Sprite , a dummy type constructor is used, and since this applies to all JavaScript, Moveable instanceof Sprite are considered instanceof Sprite .
This is not โshort and clear,โ as you requested, but the only choice is to completely skip the prototypes and assign the elements directly inside the constructor.
Edit: As @Raynos points out, you also want to set the constructor property (which runs by default JavaScript but gets lost as soon as you reset Moveable.prototype )
Moveable.prototype.constructor = Moveable;
casablanca
source share