Finding a "safety syntax" for classes

Allen Wirfs-Brock allen at wirfs-brock.com
Fri Mar 23 09:09:26 PDT 2012


On Mar 23, 2012, at 2:48 AM, Andreas Rossberg wrote:

> On 23 March 2012 08:42, Claus Reinke <claus.reinke at talk21.com> wrote:
> - would it make sense to name the constructor after the class
>   (avoiding 'constructor' and 'new')?
> 
> -1.
> 
> I always considered this a bad choice of C++-derived class systems. It violates Don't-repeat-yourself, and thus is annoying e.g. when you rename things. It is less searchable and less readable locally, because you have to take the name of the surrounding class into account to decide what kind of declaration you are looking at. And it doesn't scale to anonymous classes, in case these ever become an option for ES


Not to mention that there is no particular reason than instance method can't have the same name as its class:

class Point {} {
   constructor(x,y) {
      thls.x = x;
      this.y = y;
    }
    Point () {
       return this
    }
}

Allen

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120323/18b4954d/attachment.html>


More information about the es-discuss mailing list