早上好,我正在从JavaScript的函数式编程方法转向面向对象的方法学,并且有一个问题。在函数式编程我可以调用一个函数另一个函数内。例如:JavaScript OOP参考方法
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()' –
就像一个资源可以帮助你一样.. http://stackoverflow.com/a/13074081/1257652 –