私は次のチュートリアルで、俳優のスーパークラスから継承する宇宙船を作成しています。宇宙船のコンストラクタを作成するときに、私は誰が私にActor.call(このシーン、x、y)の目的を伝えることができるスーパークラスコンストラクタを呼び出すHTML5ゲーム
Actor.call(このシーン、x、y)を使用した俳優のコンストラクタを呼び出します私はそれがActorのプロパティ(this.scene = scene、this.x = x、this.y = y)を継承できるので、これを繰り返す方法であると思いますか?
function Actor(scene, x, y) {
this.scene = scene;
this.x = x;
this.y = y;
scene.register(this);
}
Actor.prototype.moveTo = function(x, y) {
this.x = x;
this.y = y;
this.scene.draw();
};
Actor.prototype.draw = function() {
var image = this.scene.images[this.type];
this.scene.context.drawImage(image, this.x, this.y);
};
function SpaceShip(scene, x, y) {
**Actor.call(this, scene, x, y); // call actor constructor**
this.points = 0;
}
SpaceShip.prototype = Object.create(Actor.prototype)
SpaceShip.prototype.type = "spaceShip";
SpaceShip.prototype.scorePoint = function() {
this.points++;
};
「コンストラクタとは何か」という質問は簡単ですか? – meagar
私の質問は - 宇宙船のコンストラクタでは、Actor.call(this、scene、x、y)の目的は何ですか? – stckpete
Java(またはそれに類するオブジェクト指向言語)の経験はありますか?また、プロトタイプの継承がjavascriptでどのように機能するか知っていますか? – valepu