Skip to content

Instantly share code, notes, and snippets.

@aconbere
Created March 8, 2011 18:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aconbere/860700 to your computer and use it in GitHub Desktop.
Save aconbere/860700 to your computer and use it in GitHub Desktop.
mixin = function (target, mixin, recurse) {
// Create an instance if we get a constructor
var m;
if (typeof mixin == 'function') {
m = new mixin();
}
else {
m = mixin;
}
var baseObj = {};
for (var p in m) {
// Don't copy anything from Object.prototype
if (typeof baseObj[p] == 'undefined' || baseObjj[p] != m[p]) {
if (recurse && typeof m[p] == 'object' && m[p] !== null && !m[p] instanceof Array) {
fleegix.mixin(target[p], m[p], recurse);
}
else {
target[p] = m[p];
}
}
}
return target;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment