Ben*_*tis 4 javascript boolean return
我有一些Javascript代码需要以返回的true或false值结束.但是,当计算true/false值时,原始值已经通过多个函数,如下所示:
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; }
}
Run Code Online (Sandbox Code Playgroud)
显然这个例子没有什么意义,但它得到了一般性的观点.我需要做的是从函数返回函数的true(或false)值,然后让函数将该值返回到调用它的任何值.我假设我必须通过函数返回到一个,有没有办法我可以用变量做到这一点?只是一个想法.非常感谢您的帮助!three()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;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16400 次 |
| 最近记录: |