Augusto Moura (2019-01-16T16:40:53.000Z)
In the proposal:
> ``` js
> class SizedArray<size> extends Array {
>
>   constructor(...args) {
>     if(args.length > size) throw new SyntaxError('Argument size is too big.')
>     super(...args)
>   }
>   push(i) {
>     if(this.length + 1 > size) throw new SyntaxError('Cannot push items anymore, array too big.')
>     super.push(i)
>   }
> }
> ```
> Usage:
> Usage is simple, and obvious.
> ``` js
> // ...
> let somethingElse: A<Number> = new A<Number>;
> ```

I don't think the syntax is obvious. What will happen in the if inside
the constructor? What value `size` would receive? Infinity? undefined?
The `Number` function?
That's no way templates will ever work like that in Javascript, it
doesn't makes any sense, C++ templates were implemented to support
generic static allocation and safe typings, neither of this features
applies to Javascript (and probably never will). Your example could
easily be written with constructor arguments (like any sane OOP
language), that's not a problem to be solved here

``` js
class SizedArray extends Array {
  constructor(size, ...args) {
    if (args.length > size) throw Error();
    super(args);
  }
}
```

Em ter, 15 de jan de 2019 às 17:01, IdkGoodName Vilius
<viliuskubilius416 at gmail.com> escreveu:
>
> See: https://github.com/CreatorVilius/ecmascript-proposals/blob/master/proposal-class-templates.md
>
>
>
> I think having Class Templates in JavaScript would be awesome thing and should be implemented. But that’s just my opinion.
>
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



-- 
Atenciosamente,

Augusto Borges de Moura
augusto.borgesm at gmail.com (2019-01-16T17:07:05.822Z)
In the proposal:
> ``` js
> class SizedArray<size> extends Array {
>
>   constructor(...args) {
>     if(args.length > size) throw new SyntaxError('Argument size is too big.')
>     super(...args)
>   }
>   push(i) {
>     if(this.length + 1 > size) throw new SyntaxError('Cannot push items anymore, array too big.')
>     super.push(i)
>   }
> }
> ```
> Usage:
> Usage is simple, and obvious.
> ``` js
> // ...
> let somethingElse: A<Number> = new A<Number>;
> ```

I don't think the syntax is obvious. What will happen in the if inside
the constructor? What value `size` would receive? Infinity? undefined?
The `Number` function?
That's no way templates will ever work like that in Javascript, it
doesn't makes any sense, C++ templates were implemented to support
generic static allocation and safe typings, neither of this features
applies to Javascript (and probably never will). Your example could
easily be written with constructor arguments (like any sane OOP
language), that's not a problem to be solved here

``` js
class SizedArray extends Array {
  constructor(size, ...args) {
    if (args.length > size) throw Error();
    super(args);
  }
}
```