好吧,刚刚解决了一个问题,其中this refered to the wrong scope。现在我有另一个问题。JavaScript是指方法内的一种方法?
所以我要调用一个方法是内一个方法。但我不知道怎么回事,检查此来源:
function someObj() {
var self = this;
this.someMethod1 = function() {
var elementBtn = document.getElementById('myBtn');
elementBtn.onclick = function() {
self.someMethod2.methodMethod();
//I want this.someMethod2.methodMethod() to be called
//...but I get an big error instead. Is it even possible?
//this.someMethod2() works fine.
};
};
this.someMethod2 = function() {
this.methodMethod = function() {
alert('THIS IS THE ONE I WANTED!');
};
alert('NO, NOT THIS!');
};
}
错误消息:
Uncaught TypeError: Object function() { ...
你能不能举个例子?我对JS中的对象和函数有些困惑。 ^^ – jamietelin 2012-02-07 09:19:32