> const Person = Mammal <| {
>     name: 'John Doe',
>     constructor(sex,name) {
>         super.constructor(sex);
>         this.{name}
>    }
> }
> 
> console.log(typeof Person);  //'object', not 'function'
> console.log(Person.name);  //'John Doe'
> 
> Person is the prototypal person.  You would then really like to create new 
> Person instances like:
> 
> let joe = new Person('male','Joe Smith'); // means roughly joe = 
> Object.create(Person).constructor('male','Joe Smith')
> 
> console.log(joe.name);  //'Joe Smith'
> console.log(Object.getPrototypeOf(joe).name);  //'John Doe'
> 
> However, new currently throws when applied to non-function objects.   This is 
> something I would like to fix for ES.next.

I’d still be a huge fan of that, e.g.:

operator new(proto, ...args) {
    let o = Object.create(proto);
    o.constructor(…args);
    return o;
}

Obviously, you would use Person.isPrototypeOf(p) instead of p instanceof Person.

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