나는 직접적인 대답은 여기 없다고 알고 있지만, 가능하다고 생각하는 부부와 이야기를 나눴습니다. 여기 내 코드는 다음과 같습니다.이미 다른 클래스에서 상속 한 클래스를 확장 할 수 있습니까?
var Tile = function(xPos, yPos, state) {
this.createTile(xPos, yPos, state);
}
Tile.prototype = new createjs.Shape();
Tile.prototype.createTile = function(xPos, yPos, state) {
// debugger;
this.x = xPos;
this.y = yPos;
this.onState = state;
var fillCommand = this.graphics.beginFill("#969696").command;
var shapeCommand = this.graphics.drawRoundRect(0, 0, 50, 50, 10).command;
this.on("click", function(){this.toggleState(fillCommand);});
stage.addChild(this);
stage.update();
}
Tile.prototype.toggleState = function(fillCommand) {
if (this.onState === true) {
fillCommand.style = "#969696";
stage.update();
this.onState = false;
} else if (this.onState === false) {
fillCommand.style = "#000000";
stage.update();
this.onState = true;
}
}
누구나 익숙하다면 Shape()가 easeljs에 구현됩니다. 기본적으로 여기에 Tile 클래스를 만들어서 눌렀을 때 색상이 바뀌는 작은 둥근 사각형을 나타냅니다. 구문 - 현명한 웹 페이지에 아무것도 표시되지 않습니다. 이미 타일을 호출하고 캔버스가 이미 설정되어있는 올바른 코드가 있거나이 코드도 여기에 넣습니다. 내가 여기서 묻는 것은,이 구현에서 올바른 생각을 가지고 있는가?
왜 직접 응답이 "아니오"입니까? 이것은 평범한 자바 스크립트 상속과 같습니다. change만이'createjs.Shape.call (this)'과 같은'Tile' 생성자 안에서'Shape' 생성자를 호출 할 수 있습니다. 또한,'Tile.prototype = Object.create (createjs.Shape.prototype)'이 일반적으로 선호됩니다. –
나는 자바 스크립트가 오직 하나의 상속만을 지원한다는 것을 알고있다. 그래서 나는 직접적인 대답이 아니오라고 말했다. 잘못인가? –