I have a JS object, in a property I use a function expression, within a variable result.
I need to populate the result variable and return it when processData has been invoketed.
Could you tell me what I'm doing wrong here, if you brief explain the problem and add a pieec of good would be great.
$(document).ready(function () {
// General Settings
var
ApiSettings = {
clientId: 'aaa',
clientSecret: 'bbb'
}
ApiSettings.uriGetToken = 'https://ccc.com/oauth/token?grant_type=client_credentials&client_id=' + encodeURIComponent(ApiSettings.clientId) + '&client_secret=' + encodeURIComponent(ApiSettings.clientSecret);
ApiSettings.token = (function () {
var result; // I'm not able to set this variable
// Make an Ajax Request
$.getJSON(ApiSettings.uriGetToken, processData);
function processData(data) {
result = data.access_token;
}
return result;
})();
console.log(ApiSettings);
console.log(ApiSettings.uriGetToken);
console.log('FINAL:' + ApiSettings.token);
});