javascript - Promises: How to pass data? -


i'm trying understand how promises works. see it's "chained callbacks"... more or less... but... it's possible extract values external value/array/object?

promise1()   .then(return x)   .then()   .then()   .then(function(x){     console.log(x);   }); 

and how can pass data first .then() fourth .then()?

any effort me understand promises appreciated.

you can need pass x value 1 then another:

promise1()     .then(function() {         return x; // "x" wrapped in resolved promise "then method"     })     .then(function(x) { // "then" pass fulfillment callback value inside promise taken in input, "x" value         return x; //same above, return "x" value pass next "then" function     })     .then(function(x) { // same above         return x; // same above     })     .then(function (x) {          console.log(x); // here can access "x" value , print     }) 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -