Classes: suggestions for improvement

Bob Nystrom rnystrom at google.com
Tue Jun 14 13:21:27 PDT 2011


On Tue, Jun 14, 2011 at 1:05 PM, felix <felix8a at gmail.com> wrote:

> How about using "prototype" or "proto" as the keyword instead of "class"?
>
> It's a declaration of a prototypical object used to generate other objects.
>
> "prototype" is already a familiar word to JS programmers; this is just
> extending its use into a new but similar context.
>
> "prototype" has a looser, more script-y feel than "class".
>
> "prototype" has less baggage than "class"; JS is likely to be the only
> prototypal-inheritance language that most programmers know.
>
> "proto Point { }" reads well in English, it's a proto-Point.
>

I think that's been considered before. My complaint with it is that Point *
isn't* a prototype. It's a constructor function whose .prototype property is
the prototype. In other words, the object bound to the name Point isn't the
prototypical point. It's a constructor/class-thing/type-object kind of
thing. It *owns* the Point prototype, but isn't it itself.

"class" isn't a perfect term for it, but it's not a bad one. Point is a
thing that lets you create instances that all have certain properties in
common. It can be used in instanceof checks to see if an object is of its
type. That sounds a good bit like a class to me, at least informally.

Pragmatically, many experienced JS developers already refer to constructor
functions as defining classes, and a number of existing frameworks use that
terminology for their inheritance systems. Using the class keyword (which is
conveniently reserved just for this use) builds on that.

- bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110614/597c5f3e/attachment.html>


More information about the es-discuss mailing list