Created
March 8, 2011 18:22
-
-
Save aconbere/860700 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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