Skip to content

Instantly share code, notes, and snippets.

@tompazourek
Last active June 17, 2016 22:21
Show Gist options
  • Save tompazourek/92ed322586fd95b5a41ad43e3073c7c3 to your computer and use it in GitHub Desktop.
Save tompazourek/92ed322586fd95b5a41ad43e3073c7c3 to your computer and use it in GitHub Desktop.
JS inheritance
var Bar = (function(parent) {
// constructor
var cls = function Bar(/* ... */) {
parent.call(this, /* ... */);
/* ... */
};
// inheritance
inherits(cls, parent);
// methods
cls.prototype.baz = function() {
/* ... */
);
return cls;
})(Foo);
var inherits = function(child, parent) {
child.prototype = Object.create(parent.prototype);
child.prototype.constructor = child;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment