classes and enumerability

Caitlin Potter caitpotter88 at gmail.com
Wed Dec 24 17:24:42 PST 2014


An assessor can produce data which is desired serialization, period. For instance, a setter might be used to enforce rules on valid values, which should still be serialized. A proxy could do this too, but nobody really wants to use proxies for everything.

On the other hand, certain assessor properties you would definitely not want to serialize, to avoid providing sensitive, unnecessary, or circular data to a serializer. So it's hard to pick the most sensible default. 

I don't think built in accessors really matter much, because things like Array length becomes useless when serialized, but user defined accessors often aren't useless or undesirable to serialize (at least in data persistence libraries and similar things).

It's hard to produce a cohesive argument or example from a phone, though, I'll get back to this on another day.

> On Dec 24, 2014, at 7:47 PM, Andrea Giammarchi <andrea.giammarchi at gmail.com> wrote:
> 
> Out of curiosity, which accessor, being a runtime info that once trapped in a static property looses its meaning, is commonly needed for JSON ?
> 
> I am just thinking about `Array` and the fact that thanks gosh the `length` is not in. What kind of logic you have in mind?
> 
> ```js
> // to fix the exception
> // with ... a **non enumerable** method ;-)
> class SomeCase {
>   toJSON() {
>     var o = Object.assign({}, this);
>     o.accessor = this.accessor;
>     return o;
>   }
> }
> ```
> 
> case solved in few lines and yet another method, the `toJSON` one, that nobody wants to show up anywhere in an enumerable way.
> 
> Best Regards
> 
> 
> 
>> On Thu, Dec 25, 2014 at 1:17 AM, Caitlin Potter <caitpotter88 at gmail.com> wrote:
>> Supposing that methods were non-enumerable by default, would accessors be different, or also non-enumerable by default?
>> 
>> In most cases, accessors would make sense to be enumerable, e.g. for JSON serialization, but that would be sort of inconsistent and confusing if the default were different from methods
>> 
>> (Just thinking out loud)
>> 
>> > On Dec 24, 2014, at 7:09 PM, Brendan Eich <brendan at mozilla.org> wrote:
>> >
>> > Brendan Eich wrote:
>> >> There's a confounding variable: the pain of ES6s meta-object APIs, in all respects.
>> >
>> > I meant "ES5's" here, of course.
>> >
>> > Agree with Jeremy, laziness is a programmer virtue and a part of human nature. People are not bothering where they don't know better, or do perhaps know enough but don't have time and cause to take the trouble. The trouble is due to the non-default nature of non-enumerability. Arguing from that past default to (still-future for a little while!) ES6 class's prototype methods being non-enumerable is circular, if you ignore the foolish-consistency argument (which I think we should, but I"m not dismissing here -- just noting that it isn't enough to avoid circularity because of the ES5's-painful-to-use confounder).
>> >
>> > /be
>> > _______________________________________________
>> > 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/20141224/eea482f7/attachment.html>


More information about the es-discuss mailing list