Skip to content

Instantly share code, notes, and snippets.

@ValeriiVasin
Created January 2, 2012 00:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ValeriiVasin/1548808 to your computer and use it in GitHub Desktop.
Save ValeriiVasin/1548808 to your computer and use it in GitHub Desktop.
[javascript patterns] Javascript inheritance.
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