가 주어 자신을 참조하는? 객체 내부에서 사물을 참조해야하므로 외부 독립형 함수가 필요하지 않습니다.자바 스크립트, 디자인 기능은
예를 들어 함수는 ganttChart 객체의 특정 인스턴스에 정의 된 variable1/2/3을 참조 할 수 있습니다 (여러 차트 객체를 가질 수 있음).
희망이 맞습니다! EG :
function ganttChart(gContainerID) {
this.variable1 = "lol";
this.variable2 = "hai dere";
this.variable3 = "cometishian";
....
this.gContainer.innerHTML += "<div id=\"gBar" + i +
"\" class=\"gBar\" onmousedown=\"gInitBarDrag(this)\">Hello</div>";
....
gInitBarDrag = function(thisGanttObject)
{
alert(thisGanttObject.variable2);
// This line wont work because it doesn't know what ganttChart to reference!
}
}
@Tom 'this'값은 무엇을 의미합니까? –
ganttchart 개체입니다. –
@Tom "granttChart class"는 무엇을 의미합니까? granattChart는 함수이며 JavaScript에 클래스가 없습니다. –