Using monocle mustache for chaining.

Axel Rauschmayer axel at rauschma.de
Sat Nov 12 12:22:32 PST 2011


[Apologies for interrupting...]

> If we do classes, what .{ use-cases remain?

The operator allows you to use object literals (including all of the niceties that will be introduced in ES.next) where you previously had to do multiple assignments. It’s especially nice for adding things to prototypes. For example:

    function Person(name) {
        this.name = name;
    }
    Person.prototype . {
        describe() {
            return "Person called "+this.name;
        }
    };
    
    var Employee = Person <| function (name, title) {
        super.constructor(name);
        this.title = title;
    }
    Employee.prototype . {
        describe() {
            return super.describe() + " (" + this.title + ")";
        }
    };

The power of object literals will grow and the monocle operator allows us to use this power in many more places.

If find that the above pretty enough that I could make do without class declarations.

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

home: rauschma.de
twitter: twitter.com/rauschma
blog: 2ality.com





More information about the es-discuss mailing list