Учитывая приведенный ниже фрагмент кода,
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";
});
}
Я надеялся, что нижеприведенные два утешат res как «два» (решите «два»).
Но, как ни странно, i) консоли - как «один», ii) консоли - как «два»
i) two().then(function(res){
console.log(res);
});
ii) three().then(function(res){
console.log(res);
});
Может кто-нибудь объяснить, почему они так себя ведут.