gpt4 book ai didi

javascript - 如何重构 "if x return x"语句

转载 作者:行者123 更新时间:2023-12-05 06:50:15 25 4
gpt4 key购买 nike

我正在寻找重构这种“if x return x”模式的方法。这似乎是多余的。

例如:

async exampleFunction(a) {
const firstResult = await this.firstHandler(a);

if (firstResult) {
return firstResult;
}

const secondResult = await this.secondHandler(a);

if (secondResult ) {
return secondResult;
}

const thirdResult = await this.thirdHandler(a);

if (thirdResult) {
return thirdResult;
}
}

最佳答案

function exampleFunction(a) {
return this.firstHandler(a) || this.secondHandler(a);
}

关于javascript - 如何重构 "if x return x"语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66451838/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com