有人可以指出错误吗?

时间:2010-08-17 09:31:42

标签: javascript

有人可以指出这段代码中的错误吗?

function inspect(useDoubleQuotes) {
        var escapedString = this.replace(/[\x00-\x1f\\]/g, function (character) {
            if (character in String.specialChar) {
                return String.specialChar[character]
            }
            return "\\u00" + character.charCodeAt().toPaddedString(2, 16)
        });
        if (useDoubleQuotes) {
            return '"../' + escapedString.replace(/default.htm"/g, '\\"') + '"'
        }
        return "'../_+escapedString.replace(/default.htm'/g,"\\'")+"'"}function toJSON(){return this.inspect(true)}function unfilterJSON(filter){return this.replace(filter||Prototype.JSONFilter,"$1")}function isJSON(){var str=this;if(str.blank()){return false}str=this.replace(/\\./g,"@").replace(/" [ ^ "\\\n\r]*" / g, "");
        return (/^[,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]*$/).test(str)
    }

2 个答案:

答案 0 :(得分:2)

简单:在函数结束时有两个连续的return语句。第一个,我无法阅读,但我怀疑在第一个'之前错过+

编辑:这是您的错误:

  

缺少

这意味着您错过了返回语句末尾的;

        if (useDoubleQuotes) {
            return '"../' + escapedString.replace(/default.htm"/g, '\\"') + '"'
        }

答案 1 :(得分:1)

在函数末尾的两个连续返回中的第一个返回时,字符串以双引号开头,使得该行的其余部分无法使用。

查看上面的返回以使其正确(它们以相同的方式启动,语法突出显示为您指出)。

相关问题