我想知道是否有人可以澄清以下内容。
和
的区别是什么?function(arg).then((ret) => {
anotherFunc(ret);
}).catch(error)
:
function(arg).then((ret => {
anotherFunc(ret);
})).catch(error)
差异是承诺返回时的括号。
第二个例子看起来很奇怪。我认为你的问题与箭头函数语法有更多的关系。如果箭头函数只有一个参数,可以跳过括号。例如:
const logA = a => console.log(a);
const logB = (b) => console.log(b);
如你所见,logA参数没有(),logB参数有(b)。它们的工作方式完全相同,只是语法偏好。
function(arg).then((ret) => {
anotherFunc(ret);
}).catch(error)
或
function(arg).then(ret => {
anotherFunc(ret);
}).catch(error)
是一样的