Finding a "safety syntax" for classes

Axel Rauschmayer axel at rauschma.de
Wed Mar 21 12:17:46 PDT 2012


As Herby mentioned, the result of the function Class() conforms to the best practice of:

     C.prototype.constructor === C

(Given a constructor function C.) The above assertion holds for all built-ins.


On Mar 21, 2012, at 20:13 , Axel Rauschmayer wrote:

> For example (IIRC, that’s what Allen’s class operator does, I’ve also seen similar functions on the web):
> 
>    function Class(proto) {
>        let constr = proto.constructor;
>        constr.prototype = proto;
>        return constr;
>    }
>    let Point = Class({
>        constructor: function (x, y) {
>            this.x = x;
>            this.y = y;
>        }
>    });

-- 
Dr. Axel Rauschmayer
axel at rauschma.de

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

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


More information about the es-discuss mailing list