가정 JQuery와가 포함되어있는 '이'참조를 잃게 :JQuery와 크기 조정
function FixedPoint(bgWidth) {
this.bgWidth= bgWidth;
this.plot();
$(window).resize(this.plot);
}
FixedPoint.prototype.plot = function() {
console.log(this.bgWidth); //This is undefined when called by resize
}
var pt1 = new FixedPoint(1920);
플롯() 생성자 또는 초기화 모든 확인 후 호출되고 있지만, 플롯()가 크기 조정에 의해 호출 될 때 때 함수를 사용하면 더 이상 'this'를 통해 인스턴스 변수에 액세스 할 수 없습니다.
이 문제를 해결하기 위해 생성자의 크기를 조정할 수 있지만 클래스에 정리가 필요합니다.
예, 예상됩니다. 'this' 내부는 그 함수를 이벤트 콜백으로 전달할 때 이벤트의 대상입니다. –