Reputation: 14250
I am trying to call a method in the callback function.
jsTest.prototype.getTitle = function() {
thisJS=this
//the console will returns my object...so it's not undefined.
console.log(thisJS);
//codes.....
//ajax callback function
ajaxcall.callback=function(data){
//call the addName method
thisJS.addName(data, 1);
};
}
jsTest.prototype.addName=function(data, bool){
console.log(data);
}
I got an error saying
Uncaught TypeError: Cannot call method 'addName' of undefined
Are there any ways to solve this? Thanks so much!
Upvotes: 0
Views: 70
Reputation: 725
to call the method addName, you have to make a reference of that class like in OOP..
if you dont have a jsTest object created then you cant use addName
var item = new jsTest();
item.addName(data, 1);
Upvotes: 0