Created
February 12, 2015 14:20
-
-
Save stevebrowndotco/05b99d7728271112e994 to your computer and use it in GitHub Desktop.
Simple Javascript Inheritance
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 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