I see that you have already accepted the answer, however, if you take a big mental leap and keep the promise of chapters instead of chapters themselves, then the code will be greatly simplified.
Nowadays this is probably the more common approach for a fetch / cache situation.
var chapters_promise; var getChapters = function () {
What is actually promised (chapters) will be determined by the value (s) returned by the Lawnchair and this.save , so you still need to do some work.
getChapters() will always return a promise, regardless of whether the data should be retrieved or already cached. Therefore, getChapters() can only be used with the concrete methods .then() , .done() , .fail() or .always() , for example:
getChapters().then(fnLoad);
You do not have another way to access chapters , but this is reasonable, because with any call to getChapters() you do not know whether it will follow the $.getJSON() branch or the simple return branch, from which identical promises are returned.
source share