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

```js
Object.defineProperties(
  Person.prototype,
  {
    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:

```js
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 <[email protected]> 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
> [email protected]
> https://mail.mozilla.org/listinfo/es-discuss
>
>
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to