Created
August 26, 2015 03:22
-
-
Save cerebrl/12f2b2838b347a543c8c to your computer and use it in GitHub Desktop.
A mixin factory for building horizontal inheritance.
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
/** **************************************** | |
* 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