I would like to log the result of calling a method on a object.
The current script log the result of the function in the property token
literally I mean the result is the defined function.
What am I doing wrong here? Many thanks!
$(document).ready(function () {
// General Settings
var
ApiSettings = {
clientId: 'aaa',
clientSecret: 'bbb',
token: function () {
var token;
$.getJSON(ApiSettings.uriGetToken, processData);
function processData(data) {
token = data.access_token;
}
return token;
}
}
ApiSettings.uriGetToken = 'https://ccc.com/oauth/token?grant_type=client_credentials&client_id=' + encodeURIComponent(ApiSettings.clientId) + '&client_secret=' + encodeURIComponent(ApiSettings.clientSecret);
console.log(ApiSettings);
console.log(ApiSettings.uriGetToken);
var test = ApiSettings.token;
console.log(test);
});