Skip to content

Instantly share code, notes, and snippets.

@ixtli
Created July 9, 2014 16:57
Show Gist options
  • Save ixtli/d217f17738f61968bc74 to your computer and use it in GitHub Desktop.
Save ixtli/d217f17738f61968bc74 to your computer and use it in GitHub Desktop.
/**
* Apply an object's prototype as a mixin to another object's prototype
* @param {Object} destination The class to mix in to
* @param {(Object|Array)} source An object or array of objects to mix in
*/
function mixIn(destination, source)
{
if (typeof source !== TYPE_OF_ARRAY)
{
$.extend(destination.prototype, source.prototype);
return;
}
var len = source.length;
if (!len)
{
return;
}
var arr = new Array(len + 1);
arr[0] = destination.prototype;
for (var i = 1; i < len; i++)
{
arr[i] = source[i].prototype;
}
$.extend.apply($, arr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment