Created
October 4, 2013 17:24
-
-
Save mparke/6829520 to your computer and use it in GitHub Desktop.
inherits example
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
(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