An experiment using an object literal based class definition pattern
brendan at mozilla.com
Wed Aug 10 08:36:01 PDT 2011
On Aug 10, 2011, at 7:28 AM, Axel Rauschmayer wrote:
> So the consensus is to start with the simplest possible class literal? I don’t think we currently need much more than object literal syntax + sections + subclassing.
No, the class syntax includes a body which is *not* an object literal. If it were, comma separators would be mandatory between methods. That is bogus.
Class syntax has its own body plan.
> The only thing that programmers might get wrong is initializing property values in the prototype while thinking that they have created instance properties. But as that is a common pattern for giving default values to instance properties, it shouldn’t cause any problems; instance properties will be created automatically upon *assigning* a value (as opposed to reading it).
This is not so, as Alex Russell has pointed out, due to mutable objects as prototype-property values. Such values are usually bug bait where unwanted sharing with mutation is the likely result.
> In my mind, Allen has shown that such syntactic sugar can be very similar to something you build using only object literals. I find that very important – too much of a gap makes things hard to understand, once you look underneath the surface.
No argument there.
The issue is whether class syntax with appropriate semantics is worth adding too.
More information about the es-discuss