Typed Objects and Classes

Andrea Giammarchi andrea.giammarchi at gmail.com
Fri Jun 24 22:32:54 UTC 2016

FWIW I once proposed to add `type` as descriptor property (and without
success) so you could:

    age: {type: 'number', value: 0},
    name: {type: 'string', value: 'anonymous'}

in order to have a "type" defined and inheritable avoiding de-opt but
throwing instead when it's not the expected one.

It could be used to also promote an "un-typed" property like:

var obj = {id: 'abc-123'};
// later on
Object.defineProperty(obj, 'id', {type: 'string'});
And throw if different or if it was type defined already.

The `type` would work with `get`/`set` too, as well as `enumerable`,
`configurable`, and `writable` properties.

It'd be fully backward compatible (ignored) and easy to transpile via flow
like syntax.

It could also be polyfilled.

TL;DR nobody liked it ^_^

On Thu, Jun 23, 2016 at 9:00 PM, Igor Baklan <io.baklan at gmail.com> wrote:

> By the way it looks very similar to  [s-ctypes/StructType](
> https://developer.mozilla.org/en-US/docs/Mozilla/js-ctypes/js-ctypes_reference/StructType#Describing_fields)
> Although it designed for interoperability with native code (not for code
> performance improvement, or better code readability), it still might be
> interesting for you (more links can be found at [wiki/Libffi/JavaScript](
> https://en.wikipedia.org/wiki/Libffi#JavaScript) )
> _______________________________________________
> 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/20160624/3c08bd07/attachment.html>

More information about the es-discuss mailing list