Using Object Literals as Classes

Kevin Smith khs4473 at gmail.com
Fri Mar 16 23:42:11 PDT 2012


Hi Allen,

Thanks for taking the time to read and respond.  I've read your reply in
detail and I feel like it deserves a point-by-point response, but I think
the following might get us on the same page more quickly.

The important point to consider is that I'm *not* comparing this:

A.)

   let Blah = BaseClass <| function() {
   }.prototype.{
      a() {}
      b() {}
   }.constructor.{};

to this:

B.)

    function Blah()
    Blah.prototype = Object.create(BaseClass.prototype);
    Blah.prototype.a = function() {};
    Blah.prototype.b = function() {};

but rather, to what I currently use, which is this:

C.)

    var Blah = new Class({
        extends: BaseClass,
        new: function() {},
        a: function() {},
        b: function() {},
        // also
        static: { staticA: 123 }
    });

There's no question that the object literal pattern A is superior to B.
 But for me, that's a false comparison.  It's got to be better than C (or
another similar class API), or I won't use it.

What if I'd like to use the goodies from A (like private named properties
and super references), but I want the API from C?  In my review I try to
make that work, with only limited success.  That's what I mean when I say
that these features don't provide a foundation for building higher level
class abstractions.

As far as I can tell, there are two ways out of this dilemma:

1.) Allow the RHS of <| to accept a non-literal value (I noticed this
possibility under the Comments and Rationales section of the proto_operator
strawman).  This would allow me to set up the prototype chain (on a cloned
version of the input argument) from *within* my class library, instead of
outside of it.

2.) Add declarative class syntax to the language so that I can ditch the
class library.

I hope that makes sense.  Please let me know if something needs to be
clarified.

Oh yeah...

First, "super delegation" is not a "class concept", rather it is a
> fundamental concept of both inheritance or delegation based computational
> models.  Look that the self language.  You will find that it has super
>

You can definitely school me on languages any time, Allen!  I'll have to
research Self.  And I'll probably give in on this point ; )

kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20120317/82d01db8/attachment.html>


More information about the es-discuss mailing list