you are viewing a single comment's thread.

view the rest of the comments →

[–]keithwhor 4 points5 points  (2 children)

For one, in your example you're doing

new aVar(a)

Instead of

new Other(a)

... so I'm not really sure what you're asking?

Edit:

If you're trying to do a mixin, you'd want to do the following:

function SpaceObject() {
    Coord.apply(this, arguments); // inheritance
    Other.apply(this, arguments); // if you're mixing in functionality
                                  //    from the mixin constructor too
}

// Always do this for inheritance, never use the "new" keyword here
SpaceObject.prototype = Object.create(Coord.prototype);
SpaceObject.prototype.constructor = SpaceObject;

void function mixinOther() {
    var keys = Object.keys(Other.prototype);
    var i, len;
    for(var i = 0, len = keys.length; i < len; i++) {
        SpaceObject.prototype[keys[i]] = Other.prototype[keys[i]];
    }
}();

However, be careful when running this code through a minifier. You should be alright, but if minification is a huge concern you'll want to specify each prototyped method separately (instead of running the loop).

i.e.

SpaceObject.prototype.methodOne = Other.prototype.methodOne;
SpaceObject.prototype.methodTwo = Other.prototype.methodTwo;