I have the following code
var loyaltyObject = (function () {
var data = null, vm, getLoyaltyUrl;
function getData() {
$.ajax({
type: 'POST',
url: getLoyaltyUrl,
contentType: 'application/json; charset=utf-8',
dataType: 'json',
success: function (resp) {
data = resp;
},
error: function (resp) {
console.log('Error fetching offers!');
console.log(resp);
}// error(resp)
});// $.ajax()
}
...
vm = {
getData: getData,
getLoyaltyUrl: getLoyaltyUrl
};
return vm;
}());
on document.ready I call
function Init() {
window.loyaltyObject.getLoyaltyUrl = '@Url.Action("GetLoyaltyData", "Orders")';
window.loyaltyObject.getData();
}
window.loyaltyObject.getLoyaltyUrl is indeed the url but the internal getLoyaltyUrl is still undefined.
I read the following return a variable as a property about setting up a getter, but how would I perform a setter, what is the this or value I would be setting?
Also would it be comparable on most browsers?
get...are actually functions.getData?vmhas getLoyaltyUrl as a (public) property, no need for a setter. Or do you want to set it onloyaltyObject?this.getLoyaltyUrlproperty inside the method and drop the local variable.