Shijun He (2012-08-26T09:53:09.000Z)
Hi,

I don't think Array.of() is useful, just stick on array literal seems enough:

var a = [1,2,3]
var a1 = [3]

Why we need this:

var a = Array.of(1,2,3)
var a1 = Array.of(3)

Is there any special benefit I missed?


And there is another reason why I don't like Array.of() , myself write
a small library which use Array.of(type) to get a "strong-typed"
array:

var StringArray = Array.of(String)
var a = StringArray.from(['a', 1, true]) // ['a', '1', 'true']
a.push('string')  // ['a', '1', 'true', 'string']
a.push(100) // throws error

And Function.of() :

var sqrt = Function.of(Number).from(Math.sqrt)
sqrt(9) // 3
sqrt('9') // error
sqrt(9, 'unwanted') // error


--
hax
domenic at domenicdenicola.com (2014-01-03T16:24:01.110Z)
I don't think `Array.of()` is useful, just stick on array literal seems enough:

```js
var a = [1,2,3]
var a1 = [3]
```

Why we need this:

```js
var a = Array.of(1,2,3)
var a1 = Array.of(3)
```

Is there any special benefit I missed?

And there is another reason why I don't like `Array.of()`, myself write
a small library which use `Array.of(type)` to get a "strong-typed"
array:

```js
var StringArray = Array.of(String)
var a = StringArray.from(['a', 1, true]) // ['a', '1', 'true']
a.push('string')  // ['a', '1', 'true', 'string']
a.push(100) // throws error
```

And `Function.of()`:

```js
var sqrt = Function.of(Number).from(Math.sqrt)
sqrt(9) // 3
sqrt('9') // error
sqrt(9, 'unwanted') // error
```