ES3.1 Draft: String generics

Mike Shaver mike.shaver at
Wed May 7 10:12:13 PDT 2008

On Wed, May 7, 2008 at 12:17 PM, Erik Arvidsson
<erik.arvidsson at> wrote:
> The quote method needs more specification.  It needs to escape a lot
>  more characters than just single and double quotes.  The basic rule is
>  that String.prototype.quote should return a string that would be a
>  valid string literal for that string.
>  For example:
>  "a\nb".quote() => "\"a\\nb\""

I would expect that


would produce

"a\nb" (a string with 6 characters)

and that's what Firefox implements, along with a toplevel uneval that
works on strings, arrays, objects, etc..  I think it would be very
confusing for us to convert single newline characters to an escaped
backslash and 'n'!

Having a way to escape metacharacters could be valuable, but I think
much more valuable for the set of metacharacters that are meaningful
to regular expressions.  I think that's provided by more toolkits than
.quoteQuotes, and is harder to get right.


More information about the Es4-discuss mailing list