If I have the following setup:
function entryPoint (someVariable) {
getValue(arg)
.then(anotherFunction)
}
function anotherFunction (arg1) {
}
How can I make someVariable
available in anotherFunction
?
If I have the following setup:
function entryPoint (someVariable) {
getValue(arg)
.then(anotherFunction)
}
function anotherFunction (arg1) {
}
How can I make someVariable
available in anotherFunction
?
You could try this.
function entryPoint (someVariable) {
getValue(arg)
.then(anotherFunction(someVariable))
}
function anotherFunction(someVariable) {
return function(arg1) {
}
}
You can pass extra arguments with .bind
, if you want to pass the context, don't use null
and pass this
or something else instead. But after you pass the context, pass the other values that you expect as params within anotherFunction
.
function entryPoint (someVariable) {
getValue(arg)
.then(anotherFunction.bind(null, 1, 2))
}
function anotherFunction (something, other, arg1) {
// something = 1
// other = 2
// the returned value from the promise will be set to arg1
}