doSomething().then(function () { return doSomethingElse();});doSomething().then(function () { doSomethingElse();});doSomething().then(doSomethingElse());doSomething().then(doSomethingElse);是在一个网站上看到的,请问这几段js代码有什么区别
1 回答

MMTTMM
TA贡献1869条经验 获得超4个赞
上面 前者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()//a
c()//a "a inner"
e(a)
// function a(){
// console.log('a')
// return 'a inner';
//}
e(a()) // a a inner
添加回答
举报
0/150
提交
取消