0

How can I return value from code like this:

var polyfills = promise.then(function(bundle) {
    // do something to get bundle
})
  • You already have, it's just that the value _is_ bundle, and you can use it in the body of that function. You can't get the bundle value "out" of the promise, if that's sort of what you mean: what you do is chain functions on the promise (which you've assigned to the variable polyfills) and those functions will receive the value as an argument, allowing you to do stuff with it. – Dtipson Feb 25 '16 at 18:33
  • I need to use my bundle variable outside of the promise – Alexander Zalishchuk Feb 25 '16 at 18:37
  • You can't: in some ways, that wouldn't make sense. What you can do is pass the polyfills value around (it is a reference to the promise) and then when you need to _use_ the value, you'd run polyfill.then(function(bundle){ //doSomethingW/Bundle }). The point of Promises is that when they resolve w/ a value, THEN you can do something with that value. But the "then" is a function (and you would also want to handle errors). – Dtipson Feb 25 '16 at 18:41

0 Answers0