Created
January 2, 2012 00:35
-
-
Save ValeriiVasin/1548808 to your computer and use it in GitHub Desktop.
[javascript patterns] Javascript inheritance.
This file contains 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 inherit = (function () { | |
var F = function () {}; | |
return function (C, P) { | |
F.prototype = P.prototype; | |
C.prototype = new F(); | |
C.uber = P.prototype; | |
C.prototype.constructor = C; | |
}; | |
}()); | |
// usage | |
var Parent = function () {}; | |
Parent.prototype.say = function () { | |
console.log('hello'); | |
}; | |
var Child = function () {}; | |
inherit(Child, Parent); | |
var obj = new Child(); | |
obj.say(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment