encountered the following phenomena when self-learning Promise:
var promise1 = Promise.resolve([1, 2, 3]);
function promise2() {
promise1.then(function(value) {
return Promise.resolve(value);
// expected output: Array [1, 2, 3]
})
}
promise2().then(function(value){
console.log(value);
})
the error is as follows:
promise2().then(function(value){
^
TypeError: Cannot read property "then" of undefined
normal return after adding return to modify
var promise1 = Promise.resolve([1, 2, 3]);
function promise2() {
return promise1.then(function(value) {
return Promise.resolve(value);
// expected output: Array [1, 2, 3]
})
}
promise2().then(function(value){
console.log(value);
})
what is the principle behind these two?