I've recently started learning Javascript and I'm a bit perplexed by the concept of Inheritance. The code snippet below is from a phaser tutorial where Bullet seems to inherit from Sprite. Firstly, it employs the call method which, as far as I know, copies properties from one function to another. So, at this stage, Bullet basically assumes all the properties of Sprite. Call usually requires an object along with its parameters, but where do the 0,0 values come into play?
Now, after that initial step, it further goes on to use Object.create to convert the sprite object into the bullet prototype. But wasn't that already achieved through the call method?
Lastly, it sets prototype.constructor = bullet. But why is there a need for this when bullet has already been assigned as Bullet?
If anyone could shed some light on this for me, I would greatly appreciate it. Thank you!
var Bullet = function (game, key) {
Phaser.Sprite.call(this, game, 0, 0, key);
this.texture.baseTexture.scaleMode = PIXI.scaleModes.NEAREST;
this.anchor.set(0.5);
this.checkWorldBounds = true;
this.outOfBoundsKill = true;
this.exists = false;
this.tracking = false;
this.scaleSpeed = 0;
};
Bullet.prototype = Object.create(Phaser.Sprite.prototype);
Bullet.prototype.constructor = Bullet;