Skip to content

Instantly share code, notes, and snippets.

@cianclarke
Created April 30, 2013 19:06
Show Gist options
  • Save cianclarke/5491102 to your computer and use it in GitHub Desktop.
Save cianclarke/5491102 to your computer and use it in GitHub Desktop.
Functional Inheritance
var autoMobile = function(config) {
var that = {};
that.getName = function() {
return config.name;
};
that.getNumberOfWheels = function() {
return config.wheels;
};
return that;
}
var car = function(config) {
var that = autoMobile(config); // No need for new keyword!
that.getName = function() {
return 'Car: ' + config.name;
}
return that;
}
var miniCooper = car({name : "Mini Cooper", wheels: 4});
console.log(miniCooper.getName());
console.log(miniCooper.getNumberOfWheels());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment