猿问

以下js代码有什么不同,求解

doSomething().then(function () {

  return doSomethingElse();

});


doSomething().then(function () {

  doSomethingElse();

});


doSomething().then(doSomethingElse());


doSomething().then(doSomethingElse);

是在一个网站上看到的,请问这几段js代码有什么区别

千巷猫影
浏览 478回答 1
1回答

MMTTMM

上面 前者return 后面表示的是函数的返回值是doSomethingElse(),而后者没有指定 return默认返回值是undefined下面,无论doSomethingElse()还是doSomethingElse都表示函数的一个参数。简化版例子function a(){    console.log('a')    return 'a inner';}function b(){    a()}function c(){    return a()}function e(fn){    console.log(fn)}b()//ac()//a  "a inner"e(a) // function a(){//    console.log('a')//    return 'a inner';//}e(a()) // a   a inner
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答