0

I want to pass the previously resolved, returned data and an additional parameter within a promise chain. See the example for clarification.

Below functions both return a Promise and are properly executed. It's really just about passing additional parameter.

Lets consider a Promise chain like:

API.getSomething(id).then(API.processIt)


getSomething function(id) { returns a promise with data }

processIt function(data) { process the returned data }

With a syntax like above it works fine. Once I add additional parameter:

API.getSomething(id).then(API.processIt(data, "random"))

processIt function(data, misc) {...} it does't work anymore. 

Is there a way to pass additional parameters within a Promise chain using the result of the previous executed Promise without any additional library?

It's not about the design of the whole chain. I know, the problem could be bypassed with a different design but due to changes in some APIs that's the way I have to handle with the problem.

1 Answer 1

2

On this line

API.getSomething(id).then(API.processIt(data, "random"))

You are trying to pass function as reference but you are invoking the function instead.

Try

API.getSomething(id).then(function(data){
    API.processIt(data, "random");
});
Sign up to request clarification or add additional context in comments.

1 Comment

You are right, my bad. Thanks for the help! Solves my problem

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.