0

Let's say I have a promise p. I have the following code:

var entries = getEntries();

var getEntries = function() {
    ...SOME_CODE...
    return p.then(function(result) {
        return result;
    });
}

Using the debugger, I can see that result has the data that I want. How can I save it to the global variable entries (getEntries() currently returns an undefined value)?

Kyle
  • 30
  • 6
  • You don't. You couldn't use the global variable anyway without having waited for the promise. So just return a promise from `getEntries` and store that. – Bergi Jan 22 '18 at 01:14
  • 1
    If you still want to do it: `var entries; getEntries().then(result => { entries = result; }, console.error);` – Bergi Jan 22 '18 at 01:15
  • `getEntries() currently returns an undefined value` - no, it returns a `Promise` that will resolve to `result` – Jaromanda X Jan 22 '18 at 01:17

0 Answers0