Minimalist Classes

Brendan Eich brendan at mozilla.com
Wed Nov 2 10:16:16 PDT 2011


On Nov 2, 2011, at 6:26 AM, Jeremy Ashkenas wrote:

> That said, we should take care to have the two things be fully consistent: A class body should *be* an object literal, with no subtle differences in the grammar leading to stumbling blocks down the line. If class bodies can have:
> 
> class Runner {
>   run() {
>     ...
>   }
>   private quit() {
>     ...
>   }  
>   const speed: 10
> }
> 
> ... then an object literal should equally be able to have an identical body:
> 
> var runner = {
>   run() {
>     ...
>   }
>   private quit() {
>     ...
>   }  
>   const speed: 10
> };
> 
> ... as const properties and private methods on single objects are just as useful and important as const properties and private methods on objects that happen to be instances of a class.

I quite agree -- but I was focused on classes in that gist, not ready to take on object literals. I am sure Allen agrees, and probably most of TC39. We'll see.


> (Full Disclosure: I'm still very opposed to const, private, and their object-lockdown friends, but that should have no bearing on Brendan's proposal.) 

Sometimes you need to lock a door. Not having these facilities means you can't guarantee certain invariants. OTOH I bet you're worried everyone will do the stupid thing and lock down by default. That's not likely to survive on github or any JS library ecosystem where consumers have choice, so why worry?

As for private, if it's ok for Ruby to have @vars, it's ok for JS :-P.

/be
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20111102/d5f398ac/attachment.html>


More information about the es-discuss mailing list