Umair A.
Umair A.

Reputation: 6873

Can somebody point out the error?

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)
    }

Upvotes: -1

Views: 66

Answers (2)

BoltClock
BoltClock

Reputation: 724452

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, '\\"') + '"'
        }

Upvotes: 1

Berzemus
Berzemus

Reputation: 3658

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).

Upvotes: 1

Related Questions