In dem Tutorial, das ich folge, erstelle ich ein Raumschiff, das von der Superklasse Actor erbt. Wenn das Raumschiff Konstruktor erstellen, rufe ich den Schauspieler Konstruktor Actor.call (this, Szene, x, y)HTML5 Spiel Aufruf super Klasse Konstruktor
Kann mir jemand sagen, den Zweck des Actor.call (this, Szene, x, y) Ich nehme an, dass es eine Möglichkeit ist, Wiederholungen zu vermeiden, da ich die Eigenschaften des Actors erben kann (this.scene = scene, this.x = x und 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++;
};
Ist Ihre Frage einfach "was Konstrukteure sind"? – meagar
Meine Frage ist - Im Raumschiff Konstruktor, was ist der Zweck von Actor.call (this, scene, x, y) – stckpete
Haben Sie Java (oder eine ähnliche objektorientierte Sprache) Erfahrung? Wissen Sie auch, wie die prototypische Vererbung in Javascript funktioniert? – valepu