this.pic_w, this.pic_h와 같은 메소드가있는 Pic 클래스가 있습니다. 클래스의 메서드 중 하나에서 Image 객체를 초기화하고 그 중 하나의 메서드를 다시 작성합니다. Pic의 메소드 중 하나에 있지만 Pic에서 상속하지 않는 Image 재정의 메소드에서 내 Pic 변수 (this.pic_w, this.pic_h)에 액세스하려면 어떻게해야합니까? 일반적으로이 같은 폐쇄 내의 개체에 대한 참조를 저장하여 수행Javascript의 참조 클래스 컨테이너
Pic.prototype = new DaVinci();
Pic.prototype.constructor = Pic;
function Pic(canvas) {
this.canvas = canvas;
this.pic = "";
this.resize_w = 200;
this.resize_h = 200;
this.pic_w;
this.pic_h;
}
... 일부 다른 방법 ...
Pic.prototype.draw = function(img_src, pos_x, pos_y) {
this.setPos(pos_x,pos_y);
this.setPic(img_src);
var ctx = this.setWidget();
var x = this.pos_x;
var y = this.pos_y;
var img = new Image();
img.src = this.pic;
img.onload = function() {
// How can I access Pic class methods and variables from here?
ctx.drawImage(img, x, y, this.width, this.height);
}
}
일부 코드 공유. 일반적인 질문은 자동차 엔진까지 휴대 전화를 들고 정비공에게 무엇이 잘못되었는지 묻는 것과 같습니다. – Geuis