函数具有不一致的返回点 [英] Function has inconsistent return points

查看:66
本文介绍了函数具有不一致的返回点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我写的一些javascript上运行Intellij的检查时,它报告

When running Intellij's inspections on some javascript I wrote, it reports


函数'createPages'在第35行有不一致的返回点

function 'createPages' has inconsistent return points at line 35

但我不确定这意味着什么,或者如何解决这个问题。

But I'm not sure what it means, or how to solve this issue.

该函数如下所示:

function createPages(noOfCounts) {
    var default_page = 1, default_count = 15;
    if (noOfCounts != "" && noOfCounts != null) {
        if (noOfCounts > default_count) {
            try {
                var tempVal = parseInt(noOfCounts / default_count);
                jQuery("#page").val(tempVal);
                return true;
            }
            catch (e) {
                alert('Error . ' + e);
            }
        } else {
            alert("It should not be less than the 15 and should be a number");
            return false;
        }
    }
    else {
        jQuery("#page").val(default_page);
        return true;
    }
}

正如此调用:

var valid = createPages(noOfCounts);


推荐答案

你的函数将(实际上)返回 undefined 隐含地达到 alert('Error。'+ e); ,因为执行将到达函数的末尾而没有显式返回

Your function will (in effect) return undefined implicitly after it reaches alert('Error . ' + e);, because execution will reach the end of the function without an explicit return.

因此可能确保通过函数的所有代码路径显式返回一个值将被删除IntelliJ错误。

So probably making sure that all code paths through the function return a value explicitly will get rid of the IntelliJ error.

这篇关于函数具有不一致的返回点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆