> On the other hand, perhaps we could flip the bit the other way, and unify on 
> "extend" instead of <|. In scala, the is both a "class" and "object" syntax 
> that is kind of similar to the situation we currently have creating objects 
> with object literal notation and class literal notation.

I know what you mean (it’s why I like “prototypes as classes”), but there is an 
asymmetry in JavaScript and I’ve made my peace with the fact that it won’t go 
away:

1. Before an instance has been created, the closest analog of a class is the 
constructor.
2. After an instance has been created, the closest analog of a class is the 
instance’s prototype.

Example: while you write obj instanceof MyClass, what you check is 
MyClass.prototype.isPrototypeOf(obj).

Both Allen’s <| operator for functions and the class literals do a very good 
job of hiding that asymmetry. Most programmers are used to having an explicit 
class construct (e.gl those coming from Python, PHP, Java, etc.). Class 
literals provide such a construct for JavaScript, but are still close enough to 
what we currently have to do manually that they do not go too much against the 
JavaScript grain.

What do you think about the following variation of Allen’s pattern?

    const ClassName = SuperClass <| function(/*constructor parameters */) {
        //constructor body
        super.constructor(/*arguments to super constructor */);
        this.{
            // per-instance properties
        };
    }.{
        prototype: {
            // methods
        },
        // class (ie, constructor) properties
    }

Requirement: The .{} operator extends recursively if there is a name clash. 
Otherwise, the prototype cannot be extended this way.

-- 
Dr. Axel Rauschmayer

[email protected]
twitter.com/rauschma

home: rauschma.de
blog: 2ality.com

_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to