我想在一行上有一个 javascript return 关键字,而它实际返回的东西在下一行。 在 python 中,这类似于
return \
someValue
但是由于语句终止分号的可选性和 javascript 中没有行继续符,我想出的唯一方法是 hackish
return false ||
someValue;
动机: 我的实际代码是这样的。在开发过程中,我有时会注释掉第二行以在 GlobalScope.doSomething() 和 myThing.doSomething() 之间切换。诚然,这是一个小问题。
return false ||
myThing.
doSomething()
.then(...)
.then(...)
.
最佳答案
通常的方法是将链接的对象放在与return
相同的行中:
return myThing
.doSomething()
.then(...)
.then(...);
或
return myThing
.doSomething()
.then(...)
.then(...);
但是如果你坚持单独的行和额外的缩进,你也可以使用括号:
return (
myThing
.doSomething()
.then(...)
.then(...)
);
关于javascript:让返回语句跨越多行的简洁方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56065730/