Skip to content

Instantly share code, notes, and snippets.

@cerebrl
Created August 26, 2015 03:22
Show Gist options
  • Save cerebrl/12f2b2838b347a543c8c to your computer and use it in GitHub Desktop.
Save cerebrl/12f2b2838b347a543c8c to your computer and use it in GitHub Desktop.
A mixin factory for building horizontal inheritance.
/** ****************************************
* Utility file
* mixin.js
* @returns [object]
*/
function mixinFactory() {
var len = arguments.length,
i = 0,
finalObj = {};
function copyMethods(obj) {
var j = 0,
keys = Object.keys(obj),
len = keys.length;
for (j; j < len; j++) {
// Check if value is a function
if (obj[keys[j]].call && obj[keys[j]].apply) {
finalObj[keys[j]] = obj[keys[j]];
}
}
}
for (i; i < len; i++) {
// Check if value is an object
if (arguments[i] === Object(arguments[i])) {
copyMethods(arguments[i]);
}
}
return finalObj;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment