Hello this is a question to help me understand how Promises .then
returns work. The question is: how can I scoped variables to the second .then chained function?
Here is a jsbin http://jsbin.com/xacuna/edit?js,output
I can access the global variables, and pass in the scoped variables to the first then, but not after.
let innerReturnFunction = (res, myName) => {
/* this works */
console.log(`hi from inner name: ${myName}`)
return res
}
let getInnerFuncVariable = () => {
var myName = 'arturo'
return fetch('https://httpbin.org/get')
.then(function (res) {
myName = 'Bob'
return innerReturnFunction(res, myName);
})
.then(function (res, myName) {
/* doesn't work, how can I access myName */
console.log(`in first then ${res.url}, ${myName}`)
});
}
getInnerFuncVariable().then(function(res, myName) {
/* how can I access myName */
console.log(`last called ${myName}`)
})