On Fri, Oct 21, 2011 at 9:36 AM, Axel Rauschmayer <[email protected]> wrote:

> In a vein similar to making [] available to collections, one could make
> "new" and "instanceof" available to other inheritance schemes.
>
> For example:
>
> // “Meta-class” for prototypes as classes/instantiable prototypes
> function ProtoExemplars() {}
> ProtoExamplar.prototype.{
>    operatorNew(...args) {
>        let inst = Object.create(this);
>        return inst.constructor(...args);
>    },
>    operatorInstanceof(lhs) {
>        return this.isPrototypeOf(lhs);
>    }
> };
>

More entirely unsubstantiated personal opinion based on a few days
experience:

Gonzala's https://github.com/Gozala/selfish does this now and with nicer
syntax.

One subtle point I missed about his approach: instance (member) variables
are created in initializers, not as literals, unless you intend to make the
variable part of a prototype. This could be stumbling block for Java
converts, who expect declarative members.

Only bump so far: XMLHttpRequest.apply fails and you can't run
XMLHttpRequest.prototype.addEventListener unless you run XMLHttpRequest() on
the object. So I could not figure out how to inherit from XMLHttpRequest.

jjb
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss

Reply via email to