function makeHttpRequest(url, success) {
$.ajax({
url: url,
dataType: "jsonp",
crossDomain: true,
mimeType: 'application/javascript',
async: false,
success: success
});
}
var actions = {
get_min_hit_list_bounty: function (user_id) {
makeHttpRequest("get_min_hit_list_bounty?target_id=" + user_id + "&", function (data) {
var data = data['body'],
xml = convert(data);
this.min_cost = $(xml).find('min_cost').text();
this.cost = function () {
return this.min_cost;
}
});
}
};
var myBounty = new actions.get_min_hit_list_bounty(user);
alert(myBounty.cost());
I cannot return anything from this type of object. I’ve read plenty on using prototype and using “this” to make it public, but I’m not getting any where. Could someone please explain why this does not work?
TypeError: Object [object Object] has no method ‘cost’
I believe it should look like this:
You have to understand how asynchronous code works. It is not just a set of instructions that executes consequtively. Think of it in terms of events and callbacks.
Google should help.