如何检查两个单独函数的执行结果

How two check results of execution of two separate functions?

本文关键字:函数 单独 执行 结果 两个 何检查 检查      更新时间:2023-09-26

我正在两个单独的模块中检查数据,用于两个不同的目的。例如:

//first Module
var moduleOne = (function(){
    function typeCheck(data) {
        if(typeof data == "string") {
            return true;
        }
        return false;
    }
    return {
        typeCheck: typeCheck
    }
}());

我的第二个模块是:

//second Module
var moduleTwo = (function(){
    function lengthCheck(data) {
        if(data.length > 4){
            return true;
        }
        return false;
    }
    return {
        lengthCheck: lengthCheck
    }
}());

当两个模块都产生false时,我想提醒数据是错误的。

//let str variable be an example to run those functions
var str = "string-data"
moduleOne.typeCheck(str);
moduleTwo.lengthCheck(str);

但是,如果仅在一种情况下false数据,则其他一切都按原样工作。

不确定我是否了解项目结构 - 但我认为这应该有效:

    if(!moduleOne.typeCheck(str) && !moduleTwo.lengthCheck(str)){
        alert('Data is wrong!');
    }