Skip to content

Instantly share code, notes, and snippets.

@RudyLu
Created May 12, 2014 09:37
Show Gist options
  • Save RudyLu/017f0a283df87008bf2e to your computer and use it in GitHub Desktop.
Save RudyLu/017f0a283df87008bf2e to your computer and use it in GitHub Desktop.
JS inheritance
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