3 回答

TA贡献2036条经验 获得超8个赞
如果 a 为空,我不希望 f1 继续使用 console.log()
在这种情况下,您必须测试函数a内的值f1:
function f1(a) {
a = f2(a);
// do some other stuff
if (a == null) return;
console.log("I don't want the function f1 to log this.")
}
function f2(a) {
if (a == null) {
console.log("enters here")
return;
}
return a;
}
f1(null)

TA贡献1802条经验 获得超5个赞
如果是,您可以存储 的最后一个值a并退出。tempnull
function f1(a) {
let temp = a;
a = f2(a);
// do some other stuff
if (temp === null) return;
console.log("I don't want the function f1 to log this.");
}
function f2(a) {
if (a == null) {
console.log("enters here");
return;
}
return a;
}
f1(null);

TA贡献1868条经验 获得超4个赞
只返回假
function f1(a) {
a = f2(a);
// do some other stuff
if (!a) return
console.log("I don't want the function f1 to log this.")
}
function f2(a) {
if (a == null) {
console.log("enters here")
return false;
}
return a;
}
f1(null)
添加回答
举报