What’s wrong with my function for JavaScript mixins?

I’m trying to get an example working for functional mixins in JavaScript.

http://jsfiddle.net/xe207yec/3/

The function is supposed to create a new object from the old, add the properties from the mixin object to it, and return the new object – all the while not mutating the old object so that it can be used as expected.

var plusMixin = function(oldObj, mixin) {
    var newObj = oldObj;
    newObj.prototype = Object.create(oldObj.prototype);
    for (var prop in mixin) {
        if (mixin.hasOwnProperty(prop)) {
            newObj.prototype[prop] = mixin[prop];
        }
    }
    return newObj;
};

But it’s not working. The problem is that the old object is still getting mutated.

Any idea why? Thanks!


Download whats.wrong.with.my.function.for.javascript.mixins.zip
Direct Link


Download


Download whats.wrong.with.my.function.for.javascript.mixins.zip
Mediafire


Download


Download whats.wrong.with.my.function.for.javascript.mixins.zip
Firedrive


Download

Both comments and pings are currently closed.

Comments are closed.