が考える自身を参照するには?私はオブジェクト内のものを参照する必要があるので、スタンドアロンの外部関数を望んでいません。Javascriptが、設計機能は
たとえば、関数は、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」の値は何を指していますか? –
ガントチャートオブジェクト。 –
@Tom「granttChartクラス」とはどういう意味ですか? granattChartは関数であり、JavaScriptにはクラスが存在しません。 –