Typed Objects and Classes

Isiah Meadows isiahmeadows at gmail.com
Mon Jun 27 19:34:48 UTC 2016


Descriptors are annoying to deal with, anyways IMO. If it had a
corresponding syntax, and if you could use functions/object prototypes to
type them, they might have had a little better traction, but here's my
opinion: anything type-wise that can change at runtime (like the descriptor
proposal) doesn't seem likely to gain much traction mainly because 1. it's
no better than the inline caches used now, and 2. types that are added at
runtime can't be statically analyzed (which is why people use type
annotations in the first place), and thus don't scale at all. That means
likely resistance from both implementors and users at scale, which
basically equates to it's not likely.

On Fri, Jun 24, 2016, 18:33 Andrea Giammarchi <andrea.giammarchi at gmail.com>
wrote:

> 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 <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
>>
>>
> _______________________________________________
> 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/20160627/73686e67/attachment.html>


More information about the es-discuss mailing list