Skip to content

Instantly share code, notes, and snippets.

@lgmkr
Forked from ValeriiVasin/gist:1548808
Created August 21, 2012 12:50
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 lgmkr/3415106 to your computer and use it in GitHub Desktop.
Save lgmkr/3415106 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