A variation of Allen’s Class Definition Pattern

Axel Rauschmayer axel at rauschma.de
Sun Sep 25 19:52:33 PDT 2011


I like the Class Definition Pattern and tried to make it more flexible:

    const className = superClass <| function(/*constructor parameters */) {
        //constructor body
        super.constructor(/*arguments to super constructor */);
         //per instance property definitions
        //instance properties defined on prototype
        //class (ie, constructor) properties

- Approach: Define two methods Function.prototype.withPrototype() and Function.prototype.withProperties(). The latter task could also be performed via the object extension operator – I used a method for reasons of symmetry. Both methods return "this".

- Advantages compared to using the object extension operator:
    - Can omit the class property definition (without having to append ".constructor").
    - Both “clauses” can be swapped.

Dr. Axel Rauschmayer

axel at rauschma.de

home: rauschma.de
blog: 2ality.com

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.mozilla.org/pipermail/es-discuss/attachments/20110926/d058cede/attachment.html>

More information about the es-discuss mailing list