Finding a "safety syntax" for classes

Axel Rauschmayer axel at rauschma.de
Wed Mar 21 12:13:14 PDT 2012


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;
        }
    });


On Mar 21, 2012, at 20:00 , John J Barton wrote:

> On Wed, Mar 21, 2012 at 11:52 AM, Russell Leggett
> <russell.leggett at gmail.com> wrote:
>> On Wed, Mar 21, 2012 at 2:47 PM, Allen Wirfs-Brock <allen at wirfs-brock.com>
>> wrote:
>>> 
>>> 
>>> On Mar 21, 2012, at 8:41 AM, Russell Leggett wrote:
>>> 
>>> 
>>> 
>>> On Wed, Mar 21, 2012 at 11:12 AM, Kevin Smith <khs4473 at gmail.com> wrote:
>>>>> 
>>>>> I think its easier to explain - it will actually result in a constructor
>>>>> on the prototype.
>>>>> The actual constructor function and the .constructor property really
>>>>> should always be in sync - this helps with that.
> 
> So the proposal is that the class body declares a function called
> "constructor" in with other functions that will end up on the
> [[Prototype]] but the instance created from 'new' operating on the
> class function call will have an own property "constructor" that
> points to this function. Will the property also appear on the
> [[Prototype]] under 'constructor'?
> 
> 
> jjb
> _______________________________________________
> es-discuss mailing list
> es-discuss at mozilla.org
> https://mail.mozilla.org/listinfo/es-discuss
> 

-- 
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