자바 스크립트에서 다른 클래스/인스턴스의 로컬 변수 값을 읽는 방법을 알고 싶었습니다.자바 스크립트에서 메소드의 로컬 변수 사용하기
예 : 나는 클래스의 메소드를
는 :
myClass1.prototype.myMethod0 = function()
{
this._myVar = null; //initialize this._myVar
}
myClass1.prototype.myMethod1 = function(list)
{
this._myVar = msg.list;
}
및
myClass1.prototype.myMethod2 = function()
{
//do something
// and update the list like say:
list1 = this._myVar; //access the this_myVar.
}
말할 내 다른 CALSS에서
,myClass2.prototype.myMethod = function()
{
//call the class1's method here..
myClass1.prototype.myMethod2();
}
myMethod2
는이다 콜백 그리고 저는 myClass2
에 묶습니다. list1 = this._myVar;
가 업데이트 점점되지 않고는 undefined
되고있다, myClass1.callback();
하지만 myClass1.prototype.myMethod2();
를 호출 할 때 내 문제는, :
그것은 실제로 myMethod2
는 다음과 같이 호출되는 것을 의미한다. 나는 똑같은 문제를 해결하지 못하고있다.
문제는 "this._myVar는"myclass1
이전에 method1을 호출하고 this_myVar를 설정 했습니까? –
처음에 this_myVar를 어디에 선언합니까? – Wolfram