domenic at domenicdenicola.com (2014-01-03T16:51:48.876Z)
On Thu, Dec 19, 2013 at 4:37 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote:
> Note that 'of' works to create instances of subclasses or Array (and
> typed arrays) while array literals do not.
```js
var ma = new MyArray(1, 2, 3)
```
still work.
If we want to avoid the constructor, we can :
```js
var ma = MyArray.from([1, 2, 3])
```
or just fix the constructor --- if the behavior of default constructor is
confusing why not fix it? For the built-in Array we can not, but you
already extend it here!
```js
class MyArray extends Array {
constructor(...a) { this.push(...a) }
}
```
So I still think only high-order usage for built-in `Array` is a real use
case.
On Thu, Dec 19, 2013 at 4:37 AM, Allen Wirfs-Brock <allen at wirfs-brock.com>wrote: > > On Dec 18, 2013, at 11:01 AM, Shijun He wrote: > > > ... > > > > 2) > > In fact such expressive is MEANINGLESS because we will never write `var > a = Array.of(1, 2, 3)` instead of `var a = [1, 2, 3]` > > > > Note that 'of' works to create instances of subclasses or Array (and > typed arrays) while array literals do not. > > class MyArray extends Array { } > > var ma = MyArray.of(1,2,3); > > console.log(ma instanceof MyArray); //true > > allen > var ma = new MyArray(1, 2, 3) still work. If we want to avoid the constructor, we can : var ma = MyArray.from([1, 2, 3]) or just fix the constructor --- if the behavior of default constructor is confusing why not fix it? For the built-in Array we can not, but you already extend it here! class MyArray extends Array { constructor(...a) { this.push(...a) } } So I still think only high-order usage for built-in Array is a real use case. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20131219/42dc4a7c/attachment-0001.html>