String.prototype.repeat

Peter van der Zee ecma at qfox.nl
Tue Mar 22 14:29:57 PDT 2011


On Tue, Mar 22, 2011 at 2:39 AM, Dmitry A. Soshnikov <
dmitry.soshnikov at gmail.com> wrote:

>  On 22.03.2011 23:42, David Bruant wrote:
>
> Hi,
>
> About the string_repeat strawman (
> http://wiki.ecmascript.org/doku.php?id=strawman:string_repeat), one
> alternative solution could be a two argument constructor. Something like:
> String(n, pattern). So, for the example in the strawman, it would be
> String(3, '*').
>
>
> A little bit off-topic, but not so big off-topic. Recently on Twitter there
> was a question why it's not an array of zeros:
>

Actually I think Array.fill or Array#fill should be added for one of the
reasons for repeat: it is very likely that the host environment can iterate
(or even optimize) a repeat/fill much much faster than the es interpreter
could possibly achieve through looping. Especially with larger numbers.

(I'm happy once we can use a native String#repeat :)

Otoh, I don't think the second problem David points out (generate unique
property names) should become part of the spec. Seems to me to be a rather
obscure use case.

- peter
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110322/f4c927fa/attachment-0001.html>


More information about the es-discuss mailing list