Crockford의 상속 패턴을 사용하여 기본 클래스 Shape을 생성하려고합니다. 이 기본 도형을 사용하여 원, 사각형 및 삼각형을 그려 봅니다. 나는 좀 붙어있다. 기본 메서드 호출/수정 방법을 모르겠습니다.Douglas Crockfords - 기본 메서드를 상속 된 클래스로 호출하는 방법
function points(x,y) {
x = this.x;
y = this.y;
}
function Shape() {
return {
this.points: [ ],
init : function(){
if(typeof this.context === ‘undefined’){
var canvas = document.getElementById(‘canvas’);
var context = canvas.getContext(‘2d’);
}
},
draw: function(){
var context = this.context;
context.beginPath();
context.moveTo(this.points[0].x, this.points[0].y);
for(var i=1; i< this.parameter.length; i++){
context.lineTo(this.parameter[i].x, this.parameter[i].y);
}
context.closePath();
context.stroke();
}
};
}
function Circle(x, y, r){
var points = Shape();
point.x = x;
points.y = y;
points.r = r;
var baseMethod = that.draw;
that.draw = function(){
/*how to modify the base method to draw circle*/
};
}
function Rectangle(a, b, c, d){
var points = Shape();
point.a = a;
points.b = b;
points.c = c;
points.d = d
var baseMethod = that.draw;
that.draw = function(){
/*how to call base method to draw rectangle*/
};
}
,'X = this.x'해야한다'this.x = x' (y에 대해서도 동일). 'Shape'에서 this.points = []'는'points : []'이어야합니다. 'var context ='는'this.context ='이어야합니다. –
lint your code, 그 추악한 – Raynos
일련의 선언적 진술/문구는 질문이 아닙니다 :) – vol7ron