Upon reviewing the code snippet provided, it can be seen that:
function one(){
var prm = new Promise(function(resolve,reject){
resolve("one");
});
prm.customKey = function(){
}
return prm;
}
function two(){
var prm = one();
prm.then(function(res){
return "two";
});
return prm;
}
function three(){
return one().then(function(res){
return "two";
});
}
The expectation was for both cases below to output "two":
However, oddly enough: i) displays "one" in the console, ii) displays "two" in the console.
i) two().then(function(res){
console.log(res);
});
ii) three().then(function(res){
console.log(res);
});
If anyone could shed light on why this behavior is occurring, it would be greatly appreciated.