Skip to content

Instantly share code, notes, and snippets.

@mparke
Created October 4, 2013 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mparke/6829520 to your computer and use it in GitHub Desktop.
Save mparke/6829520 to your computer and use it in GitHub Desktop.
inherits example
(function() {
function extend(obj, props) {
}
function inherits(Parent, Child) {
function Proxy() {
this.constructor = Child;
}
Proxy.prototype = Parent.prototype;
Child.prototype = new Proxy();
return Child;
}
var MyParent = function() {
this.parentValue = 10;
}
var MyChild = inherits(MyParent, function() {
// calling the prototype constructor will ensure
// we execute MyParent's initialization
MyParent.prototype.constructor.call(this);
});
// lastly, extend MyChild's prototype
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment