Hello, this is a question that will help me understand how Promises .thenreturns work. Question: how can I bind variables to the second. then chain function?
Here is jsbin http://jsbin.com/xacuna/edit?js,output
I can access global variables and transfer them to the area of ββvisible variables at first, but not after.
let innerReturnFunction = (res, myName) => {
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) {
console.log(`in first then ${res.url}, ${myName}`)
});
}
getInnerFuncVariable().then(function(res, myName) {
console.log(`last called ${myName}`)
})
source
share