Skip to content

Instantly share code, notes, and snippets.

@stevebrowndotco
Created February 12, 2015 14:20
Show Gist options
  • Save stevebrowndotco/05b99d7728271112e994 to your computer and use it in GitHub Desktop.
Save stevebrowndotco/05b99d7728271112e994 to your computer and use it in GitHub Desktop.
Simple Javascript Inheritance
function Utility(){};
var utility = new Utility();
Utility.prototype.extend = function () {
function F() {}
F.prototype = this;
return new F();
};
// USAGE
var vehicle = {
nuts: true,
bolts: true
};
var car = utility.extend(vehicle);
var plane = utility.extend(vehicle);
car.wheels = true;
plane.wings = true;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment