admin管理员组文章数量:1334953
Why is this line a valid promise:
const promise = Promise.resolve('Hello');
But not this:
const otherPromise = () => {
return Promise.resolve('Hello');
}
When trying to call the second example with:
function runOtherPromise() {
otherPromise
.then(v => console.log(v));
}
...I get TypeError: otherPromise.then is not a function
. It works fine with the first example, though. I don't understand why the second example doesn't return a promise.
Why is this line a valid promise:
const promise = Promise.resolve('Hello');
But not this:
const otherPromise = () => {
return Promise.resolve('Hello');
}
When trying to call the second example with:
function runOtherPromise() {
otherPromise
.then(v => console.log(v));
}
...I get TypeError: otherPromise.then is not a function
. It works fine with the first example, though. I don't understand why the second example doesn't return a promise.
-
4
otherPromise().then(v => console.log(v));
will do the job! – Dhaval Marthak Commented Nov 13, 2017 at 12:23
1 Answer
Reset to default 6otherPromise is a function, you should call it like below:
runOtherPromise() {
otherPromise()
.then(v => console.log(v));
}
本文标签: javascriptthen is not a functionStack Overflow
版权声明:本文标题:javascript - .then is not a function - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742310926a2450854.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论