I have the following function. What I'm trying to undestand is, why wouldn't all four variables in the apiCall
function be available to the promise resolution via then
? Is there a way to access var1
, var2
and var3
inside the then
callback? Am I misunderstanding Javascript scope or is there something else in my code that could be the culprit?
apiCall (addOrRemove, var1, var2, var3) {
debugger; // ALL VARIABLES addOrRemove, var1, var2 and var3 ARE DEFINED HERE
if (addOrRemove === 'add') {
let reduxArray = this.state.reduxArray
reduxArray.push({
var1: var1,
var2: var2
})
this.setState({
reduxArray: reduxArray
})
this.props.dispatch(actionCreator(var1, var2))
.then((response) => {
debugger; // ONLY var1 IS DEFINED HERE
})
}
...
}