好吧,这并没有真正引用错误的对象,但我不知道如何引用正确的对象.
function someObj() {
this.someMethod1 = function() {
var elementBtn = document.getElementById('myBtn');
elementBtn.onclick = function() {
this.someMethod2(); //I want this.someMethod2() to be called
//...but it tries to call elementBtn.someMethod2() i believe.
};
};
this.someMethod2 = function() {
alert('OK');
};
}
Run Code Online (Sandbox Code Playgroud)
因此,当我点击myBtn时,我想要运行someObj.someMethod2().我希望它是someObj,而不是任何其他的 someObj.但是如何?!