Created
May 12, 2014 09:37
-
-
Save RudyLu/017f0a283df87008bf2e to your computer and use it in GitHub Desktop.
JS inheritance
This file contains hidden or 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
var Class = function(parent){ | |
var klass = function(){ | |
this.init.apply(this, arguments); | |
}; | |
// Change klass' prototype | |
if (parent) { | |
var subclass = function() { }; | |
subclass.prototype = parent.prototype; | |
klass.prototype = new subclass; | |
}; | |
klass.prototype.init = function(){}; | |
// Shortcuts | |
klass.fn = klass.prototype; | |
klass.fn.parent = klass; | |
klass._super = klass.__proto__; | |
/* include/extend code... */ | |
return klass; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment