Created
August 4, 2010 14:28
-
-
Save jeffreyolchovy/508217 to your computer and use it in GitHub Desktop.
Simple inheritance model for JavaScript
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
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