首页 > 解决方案 > 为什么这个函数会从 JSLint 收到警告消息?

问题描述

我有一个运行良好的函数,但我仍然收到来自 JS Lint 的警告消息。

            function undoActionClick() {
                if (history.length <= 1) return;
                history.pop();
                contextTmp.putImageData(history[history.length - 1], 0, 0);
                updateHistorySelection();
            }

这是警告信息:Expected '{' and instead saw 'return'。代码中是否存在明显错误,还是应该忽略该消息?

标签: javascripthtml5-canvasjslint

解决方案


function undoActionClick() {
    if (history.length <= 1) {
        return;
    }
    history.pop();
    contextTmp.putImageData(history[history.length - 1], 0, 0);
    updateHistorySelection();
}

这应该没问题,这不是您的代码错误,而是JSLint.

文档中的更多信息


推荐阅读