Finding a "safety syntax" for classes

Russell Leggett russell.leggett at gmail.com
Tue Mar 20 11:22:28 PDT 2012


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. 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120320/d51df137/attachment.html>


More information about the es-discuss mailing list