Using Object Literals as Classes
herby at mailbox.sk
Fri Mar 16 09:53:29 PDT 2012
Kevin Smith wrote:
> Rather than abuse your inbox, I published this as a blog entry:
> Summary: It has been suggested that extended object literals can be
> used to define class-like abstractions, and that consequently class
> syntax is not necessary. I analyze the implications from the point of
> view of a library developer.
I've got a slightly different POV.
Yes, in a perfect world, there is no need for class constructs. All
people coming to ES learn how great and powerful it is to have the
prototypal inheritance which lets you do everything you did before and
I cherish this power and simplicity.
But, in the real world, everyone (except for the little percentage of
the ones willing to learn and go deeper) begin to rant "where are the
I _don't_ want to meat these all over. ES is fine as it is.
And to stop this "class library" proliferation (and creating code that
is much more mutually readable) one should add class constructs into the
language. But to make such construct well-blended into the language and
its prototypal nature.
First thing is, if it performs well for at least 80% of the common
cases, people will use it rather than "better, truer, real classy from
[inseet your own] library".
And second, it is not a tragedy if such classes "leak". I would even
tell it is a positive thing. If native ES.next classes are good enough
to describe class concept, but at the same time slowly learn the
must-have-classes developers that classes are nothing more than a
decoration based on the more basic elements of the language, they slowly
adopt it, step by step (singleton is probably the first to die in this
battle ;-) ).
I, personally, would live perfectly fine without class. A little more
than is already in proposals (<| for declarations; separation of
parallel hierearchy from single hierarchy) will suffice for me.
But there are different, above-mentioned reasons why native class is a
very good idea (of course, not a heavy implementation that bring
something another beyond the rich language of ES.next object literals;
but that fear could be probably buried - it seems heavy classes are not
More information about the es-discuss