I have a doubt.. if I define variables before the .then()
of a promise, I have them available inside the .then()
, am I right? This is not true with callbacks, but it should using q
promises.
To be sure of this, I am asking if the below code is correct, even in the case of multiple requests.
So the arg2
of the second .then()
is always the right one, and it's not the arg2
of the last call to myapp().
function myapp()
{
var arg1=1;
var arg2=undefined; // loaded async
var arg3=undefined; // loaded async
call_promise(arg1)
.then(function(data)
{
arg2 = data;
})
.then(function()
{
arg3 = call_function(arg2);
console.log(arg3);
})
.catch(function(err){});
}