javascript 请解释这四项承诺之间的区别:[非公开会议]

lkaoscv7  于 2022-12-25  发布在  Java
关注(0)|答案(1)|浏览(99)

已关闭。此问题需要details or clarity。当前不接受答案。
**想要改进此问题?**添加详细信息并通过editing this post阐明问题。

昨天关门了。
Improve this question
'

A) foo().then(() => bar());

B) foo().then(() => {
     bar();
   });

C) foo().then(bar());
D) foo().then(bar);

'
我需要了解其中的区别。请告诉我

zwghvu4y

zwghvu4y1#

A) foo().then(() => bar());
() => bar() -> this is a function taking no arguments running bar and returning whatever bar returns
B) foo().then(() => { bar() });
() => { bar() } -> this is a function taking no arguments running bar and returning nothing
C) foo().then(bar());
bar() -> this is whatever bar returns
D) foo().then(bar);
bar -> this is a pointer/reference to the bar function effectively it will run bar with whatever foo() returens as bar's arguments

相关问题