为了账号安全,请及时绑定邮箱和手机立即绑定

使用NodeJS Promise then 返回值的问题

使用NodeJS Promise then 返回值的问题

大话西游666 2018-09-23 20:32:43
在自学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); })运行报错如下:promise2().then(function(value){           ^TypeError: Cannot read property 'then' of undefined加入return修改后正常返回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); })想请问下这两者背后的原理是什么?
查看完整描述

1 回答

  • 1 回答
  • 0 关注
  • 3530 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信