Finding a "safety syntax" for classes

Alex Russell alex at dojotoolkit.org
Fri Mar 23 02:25:31 PDT 2012


Sorry I'm late to this party.

On Mar 20, 2012, at 6:22 PM, Russell Leggett wrote:

> 
> 
> On Tue, Mar 20, 2012 at 2:09 PM, Rick Waldron <waldron.rick at gmail.com> wrote:
> [ ... snip ] 
> class Animal {
> 
>     constructor(name){
> 
>         this.name = name;
> 
>     }
> 
>     move(meters){
> 
>         alert(this.name + " moved " + meters + "m.");
> 
>     }
> 
> }
> 
> 
> Russ, 
> 
> I'm trying to write up some supporting examples, but ran into a snag regarding "static" properties. eg
> 
> function Foo( stuff ) {
>   this.stuff = stuff || "";
> }
> 
> Foo.prototype.getStuff = function() {
>   return this.stuff;
> };
> 
> Foo.Bar = function() {
>   return new Foo("bar");
> };
> 
> 
> How would I make Foo.Bar ?
> 
> In my opinion, because it is a point of contention, there should be no special support for statics.

I agree. Modules also help to make them more-or-less moot.

> It would be written exactly as you have it above, or you could do
> 
>     Foo.{
>         Bar() {
>             return new Foo("bar");
>         }
>         //potentially more here
>     };
> 
> I will reiterate the goal here of a *safety syntax*. Right now, my goal is to just get some agreement on a class syntax where the future options are open in case we can't find something better. I would still be happy to use my minimal proposed class syntax because it gets past the hard part and nails the 80% of code that's annoying. Some support for statics could be added later if agreed upon but I'd hate to see it stop classes from happening.
> 
> - Russ
>  
> 
> 
> Rick
>  
> 
> 
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss



More information about the es-discuss mailing list