Re: Shape objects

2018-06-16 Thread Jordan Harband
See https://github.com/michaelficarra/proposal-first-class-protocols which may address what you need. > given how time-constrained most web-projects are This is no more true, or universal, for web projects than it is for any project. > shape-validating low-level library-code is poor-allocation o

Re: Shape objects

2018-06-16 Thread kai zhu
> I wish JS had Shape objects, which would not only ease performance > optimization for the benefit of JS engines > (https://youtu.be/5nmpokoRaZI?t=871 ), > but also helps for validation, like an interface > > ```js > shape Point { x: Number, y: Number, name:

Re: Shape objects

2018-06-16 Thread Bob Myers
The engines already do these optimizations. On Sat, Jun 16, 2018 at 1:27 PM Cyril Auburtin wrote: > I wish JS had Shape objects, which would not only ease performance > optimization for the benefit of JS engines ( > https://youtu.be/5nmpokoRaZI?t=871), but also helps for validation, like > an i

Re: Shape objects

2018-06-16 Thread Andrea Giammarchi
StructType never really got a chance: https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/StructType but it's also easy to have those kind of shapes in userland: ```js const shape = definition => { const keys = Reflect.ownKeys(definition); const key = k => keys.incl

Shape objects

2018-06-16 Thread Cyril Auburtin
I wish JS had Shape objects, which would not only ease performance optimization for the benefit of JS engines ( https://youtu.be/5nmpokoRaZI?t=871), but also helps for validation, like an interface ```js shape Point { x: Number, y: Number, name: String }; const p = Point({x: 1, y: 2, name: 'foo'}