Proposal: Class Templates

Michał Wadas michalwadas at gmail.com
Wed Jan 16 12:56:53 UTC 2019


Isn't it already solvable by:

const SizedArray = (size) => class SizedArray 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)
  }

}

const arr = new (SizedArray(5))?



On Tue, Jan 15, 2019 at 8:01 PM IdkGoodName Vilius <
viliuskubilius416 at gmail.com> wrote:

> 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20190116/78a63a12/attachment.html>


More information about the es-discuss mailing list