I am confused about the example from here:
https://developers.google.com/api-client-library/javascript/features/promises#context-parameter,
It is about context parameter.
I found I never have a chance to know when the results are ready.
Take the following example,
I add console.log(personFetcher.results); to the end of script, it always return empty, because it is asynchronous.
So, my problem is how can I access the results, when it's ready?
var personFetcher = {
results: [],
fetch: function(name) {
gapi.client.request({path: '/plus/v1/people', params:{query: name}}).then(function(response) {
this.results.push(response.result);
}, function(reason) {
console.error(name, 'was not fetched:', reason.result.error.message);
}, this);
}
};
personFetcher.fetch('John');