String.prototype.repeat
Dmitry A. Soshnikov
dmitry.soshnikov at gmail.com
Thu Mar 24 00:22:39 PDT 2011
On 24.03.2011 0:44, Brendan Eich wrote:
> On Mar 23, 2011, at 12:57 PM, Dmitry A. Soshnikov wrote:
>
>> 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()});
>
> Fixed, in a cheezy but I hope clear fashion.
>
Yep, it's OK now; and this `NonHoleyArray` abstraction is also
interesting. Meanwhile it's an abstraction, such a thing can be needed.
And from this viewpoint I can imagine the same `fill` or `init` method,
but which can accept not only the number of elements and the direct
value for each element, but also a fill-function (indirect value). Then
the user can do it in one pass then. E.g.:
Array.fill(5, 0); // [0, 0, 0, 0]
Array.fill(5, #{Math.random()}); [0.1, 0.3, 0.5, 1, 0]
Dmitry.
> /be
>
>> 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
>>>
>>
>> _______________________________________________
>> es-discuss mailing list
>> es-discuss at mozilla.org <mailto:es-discuss at mozilla.org>
>> https://mail.mozilla.org/listinfo/es-discuss
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110324/0631ca0f/attachment-0001.html>
More information about the es-discuss
mailing list