Correction: The code below ignores the method arguments.

> Object.prototype.new = function new() {
>    if (this instanceof Function) {
>        return new this();
>    } else {
>        return new this.constructor();
>    }
> };


Fix (not very elegant...):

Object.prototype.new = function new() {
   var constr = (this instanceof Function ? this : this.constructor);
   var instance = Object.create(constr.prototype);
   constr.apply(instance, arguments);
};

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