Fwd: Re: Minimalist Classes

David Flanagan dflanagan at mozilla.com
Tue Nov 1 22:27:02 PDT 2011


[Oops. Replied to Brendan personally rather than reply-all to the list.]

-------- Original Message --------
Subject: 	Re: Minimalist Classes
Date: 	Tue, 01 Nov 2011 22:15:42 -0700
From: 	David Flanagan <dflanagan at mozilla.com>
To: 	Brendan Eich <brendan at mozilla.com>



On 11/1/11 5:18 PM, Brendan Eich wrote:
>
>  Love it or hate it, I'm ok either way :-P. But I do crave intelligent
>  responses.
>
>
I think reusing var and const in this context will be considered a wart
on the language.  If I've got to prefix an identifier with 'this' then
it is a property, not a variable or a constant.  We all know that global
variables are properties of the global object, but we don't think of
them that way.  They're still just global variables.  So I don't think
that "cat's out of the bag" argument for using them here flies.

I've got four alternatives to suggest:

1) Class bodies are new syntax, so you can introduce new keywords,
right?  So 'prop' or 'proto'?  'static' puts a property on the class.
'private' puts a (private) property on the instance.  So 'proto' could
put a property on the prototype.

2) As others have suggested, use 'public' and 'public const' instead of
'var' and 'const'.  I'd prefer that 'public' be like 'private' and
define an instance variable (see below), though, so I don't really like
this alternative.

3) Most classical OO languages just have instance properties and class
properties.  This distinction between instance properties and prototype
properties is a JavaScript thing. And if we're trying to emulate
classical OO, then how about just dropping the ability to define data
properties on the prototype.

4) Do your class bodies allow getters and setters?  Are accessor methods
defined on the prototype an adequate substitute for data properties on
the prototype?  Probably not.  But if you're allowing 'get' and 'set' in
class bodies, it demonstrates that you can introduce new keywords in the
class body context.

Your private instance variables are quite interesting.

One nit: you're using @ as both a sigil in @name and as an operator in
other at name.  I would expect other. at name instead.

And a question: do we really need both the private declaration and the
sigil?

But more to the point, you've defined a syntax that allows us to drop
'this' from our methods!  That's seriously cool.  So cool that I expect
using private properties will become the default and normal public
properties will be the exception.  Unless... Can you also allow 'this'
to be dropped for public instance variables?  With a 'public'
declaration and/or a different sigil?  What about just a dot with
nothing on the left hand side?  Can '.foo' be shorthand for 'this.foo'?
Or are there grammatical issues with that?

     David

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111101/4e14e0bb/attachment.html>


More information about the es-discuss mailing list