Good-bye constructor functions?

Kevin Smith khs4473 at gmail.com
Mon Jan 7 21:30:03 PST 2013


I think it's arguable either way.  I mean, the initializer-only behavior
advocated by Allen et al makes the class useless when called (as opposed to
new'd).

I don't think such an opinionated approach is really necessary.  One can
account for the funky behavior of the built-ins by providing an additional
"call" hook on the class, and leave everything else as is.  When the class
is called (as opposed to new'd), it would use that hook instead of the
constructor.  ("super()" would still use the parent's constructor function.)

It could be supported with syntax like so:

    class C {
        static(...args) { /* call behavior */ }
    }

I think one could also make a case that the default behavior for such a
hook would be to "new" the class, as some built-ins do (and as many current
JS "classes" attempt to do):

    class C {
        static(...args) { return new C(...args); }
    }

This seems like a pretty clean design to me.

{ Kevin }
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20130108/acac796d/attachment.html>


More information about the es-discuss mailing list