我有一些 Javascript 代码需要以返回真值或假值结束。然而,当计算真/假值时,原始值已经通过多个函数传递,如下所示:
var txt = 'foo'
function one(txt) {
if(txt == 'foo') { two(txt); }
}
function two(txt) {
if(txt == 'foo') { three(txt); }
}
function three(txt) {
if(txt == 'foo') { return true; }
else { return false; }
}
显然这个例子没有什么意义,但它表达了一般的观点。我需要做的是从函数 three()
一直返回函数 的
,然后让函数 true
(或 false
)值>one()one()
将该值返回给调用它的任何对象。我假设我必须通过函数 two()
返回到一个,有没有办法用变量来做到这一点?只是一个想法。非常感谢您的帮助!
最佳答案
您可能想尝试以下操作(如果我正确理解您的问题):
function one(txt) {
if(txt == 'foo') return two(txt);
else return false;
}
function two(txt) {
if(txt == 'foo') return three(txt);
else return false;
}
function three(txt) {
if(txt == 'foo') return true;
else return false;
}
关于javascript - 通过多个函数返回 boolean 值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3230497/