Skip to content

Instantly share code, notes, and snippets.

@jeffreyolchovy
Created August 4, 2010 14:28
Show Gist options
  • Save jeffreyolchovy/508217 to your computer and use it in GitHub Desktop.
Save jeffreyolchovy/508217 to your computer and use it in GitHub Desktop.
Simple inheritance model for JavaScript
function extend(p, c)
{
var f = function() {};
f.prototype = p.prototype;
c.prototype = new f();
c.prototype.constructor = c;
}
function mixin(p, c)
{
if(arguments.length > 2)
{
for(var i = 2, j = arguments.length; i < j; i++)
{
c.prototype[arguments[i]] = p.prototype[arguments[i]]
}
}
else
{
for(m in p.prototype)
{
if(!c.prototype[m]) c.prototype[m] = p.prototype[m]
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment