tags:

views:

32

answers:

2

Can somebody please point out the error in this code?

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  A: 

Easy: you have two consecutive return statements at the end of your function. The first of which, I can't read but I suspect is missing a ' just before the first +.

EDIT: this is your error:

; is missing

That means you missed out the ; at the end of the return statement here:

        if (useDoubleQuotes) {
            return '"../' + escapedString.replace(/default.htm"/g, '\\"') + '"'
        }
BoltClock
even removing second return statement, Visual Studio keeps showing green curly underline
Umair Ashraf
I inserted it. Now I narrowed down the error and found error is somewhere between.return "'../_+escapedString.replace(/default.htm'/g,"\\'")+"'";
Umair Ashraf
and I corrected it myself!
Umair Ashraf
+1  A: 

On the first of the two consecutive returns at the end of the function, the string starts with a double quote, making the rest of the line unusable.

Look at the return just above to make it right (they start the same way, syntax highlighting points it out for you).

Berzemus