Jussi Kalliokoski (2012-08-28T09:10:10.000Z)
On Tue, Aug 28, 2012 at 9:59 AM, Maciej Stachowiak <mjs at apple.com> wrote:

>
> On Aug 26, 2012, at 4:30 PM, Brendan Eich <brendan at mozilla.com> wrote:
>
> > Rick Waldron wrote:
> >>> But Array.of is not. Maybe Array.new is a good name.
> >> Array.of is unambiguous with the current ES specification
> >
> > Array.new is ok too, though -- no problem with a reserved identifier as
> a property name. It's darn nice for Rubyists.
>
> Another possibility is Array.create, following the pattern of
> Object.create. "of" seems like a funky name for a constructor, to my taste.
>

True, but I'd rather see Array.create as a fix for the "one argument Array
constructor", i.e. creating an array of the specified length, without
holes. For example:

Array.create = function (length) {
  if (length === 1) return [undefined]

  return Array.apply(null, Array(length))
}

There's been some discussion of that earlier, actually [1].

My 2 cents goes to Array.fromElements, conveys very well what it does.

However, I'm still not quite sure what the use case is for this. For code
generation, if you know how many elements there are and what they are
enough to put them in the Array.of(...,...,...) call, why not just use
[...,...,...]? Unless it's supposed to be used for converting array-likes
to arrays, where I really don't think this is the best function signature.
For the dart example, why not just use [] and you avoid the gotcha?

Cheers,
Jussi

[1] https://mail.mozilla.org/pipermail/es-discuss/2012-July/023974.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120828/ffcf96c5/attachment-0001.html>
domenic at domenicdenicola.com (2014-01-03T16:44:15.134Z)
True, but I'd rather see `Array.create` as a fix for the "one argument Array
constructor", i.e. creating an array of the specified length, without
holes. For example:

```js
Array.create = function (length) {
  if (length === 1) return [undefined]

  return Array.apply(null, Array(length))
}
```

There's been some discussion of that earlier, actually [1].

My 2 cents goes to `Array.fromElements`, conveys very well what it does.

However, I'm still not quite sure what the use case is for this. For code
generation, if you know how many elements there are and what they are
enough to put them in the `Array.of(...,...,...)` call, why not just use
`[...,...,...]`? Unless it's supposed to be used for converting array-likes
to arrays, where I really don't think this is the best function signature.
For the dart example, why not just use `[]` and you avoid the gotcha?

[1]: https://mail.mozilla.org/pipermail/es-discuss/2012-July/023974.html