Minimalist (why) classes ?

John J Barton johnjbarton at johnjbarton.com
Mon Nov 14 08:48:00 PST 2011


On Sun, Nov 13, 2011 at 9:49 PM, Brendan Eich <brendan at mozilla.com> wrote:
> On Nov 13, 2011, at 9:42 PM, Irakli Gozalishvili wrote:
>
> I think this discussion drifted into slightly diff direction.
> What I intended to say was that today all major frameworks use same patter
> to do subclassing. They all implement different APIs to do the following:
> function subclass() {
>    // init ….
> }
> subclass.prototype = Object.create(superclass)
> Object.defineProperty(subclass.prototype, 'constructor', { value: subclass
> })
> subclass.prototype.method = function() {
>    //...
> }
>
> Yes, this is the heart of the matter. Not freezing, not shallow vs. deep
> property copying (where deep must deal with closures at least).

Sorry I don't understand. Every function which accepts object
references and embeds its arguments in [[Prototype]] (either in the
return value or the instance created from the return value)  faces the
copy-ish problem. As I understand it, this is part of (or all of) the
reason Allen's setPrototypeOf ( <| ) operator only allows a literal on
the right hand side.   How can this be avoided?

>
> Object.extend used in my gist is BTW same as backbone's .extend
>
> Ok, good to know. (Jashkenas, you didn't propose it!)
>
> and is just a shortcut of the code above:
> var subclass = superclass.extend({
>    initialize: function() {
>       // init ...
>    },
>    method: function() {
>       // ….
>    }
> })
> What I'm asking for is a standard function, no matter weather it's
> `Object.extend` or something else that makes it simple to do subclassing.
>
> Allen has been trying to make it be a combo of <| and .{. Agree there could
> be a method, say Object.subclass (what a concept!).

As soon as I call

  var a = b.subclass(d, e);

we have to define what happens to |d| and |e|. Isn't that exactly what
we have been discussing?

jjb


More information about the es-discuss mailing list