【发布时间】:2014-02-26 15:41:11
【问题描述】:
早上好 SO,我正在从 JavaScript 的函数式编程方法转向面向对象的方法,并且有一个问题。在函数式编程中,我可以在另一个函数示例中调用一个函数:
function a(){
// do something and when done call function b
b();
}
function b(){
// does more stuff
}
现在我正在切换到 OOP 方法,我将如何从同一对象中的另一个方法调用对象中的方法。例如:
var myClass = function(){
this.getData = function(){
//do a jquery load and on success call the next method
$('#a').load('file.asp',function(response,status,xhr){
switch(status){
case "success":
//THIS IS WHERE THE QUESTION LIES
this.otherfuntcion();
break;
}
}
}
this.otherfunction = new function(){
// does more stuff
}
}
p = new myClass();
p.getData();
我可以说 this.b() 成功调用方法 b 还是我必须做其他事情?提前谢谢你。
【问题讨论】:
-
拼写错误。
this.otherfunction() -
也可以作为一种资源来帮助您。stackoverflow.com/a/13074081/1257652
标签: javascript jquery