String.prototype.repeat
Dmitry A. Soshnikov
dmitry.soshnikov at gmail.com
Wed Mar 23 12:57:17 PDT 2011
On 23.03.2011 0:18, David Bruant wrote:
> Le 22/03/2011 02:39, Dmitry A. Soshnikov a écrit :
>> 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:
>>
>> Array(100).map(function() { return 0; }); // not the array of zeros
> It's not that much off-topic. I have made the mistake myself facing
> this issue :-) (https://bugs.ecmascript.org/show_bug.cgi?id=33#c6)
>
Yep, I see. Btw, JFTR: such a mistake currently is in this strawman
http://wiki.ecmascript.org/doku.php?id=strawman:shorter_function_syntax:
let randomArray = Array(10).map(#{Math.random()});
it's better to fix the doc.
Dmitry.
>> the answer is known of course (there's no any property in the created
>> array), but similary to your String(n, '*'), there can be also
>> Array.fill(100, 0); or Array.init(100, 0);
>>
>> P.S.: though, of course all these can be done manually in ES itself.
> Of course and these cases do not happen once a day. However, when they
> happen, it's convenient if the language offers a native construct.
>
> David
>
>>
>> Dmitry.
>>
>>> In ES5, the String constructors (String and new String) both are
>>> expected to be used with zero or one argument, so using a two
>>> argument constructor should not break the web or people's expectations.
>>>
>>> David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110323/3e1d4107/attachment.html>
More information about the es-discuss
mailing list