Created
April 30, 2013 19:06
-
-
Save cianclarke/5491102 to your computer and use it in GitHub Desktop.
Functional Inheritance
This file contains 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
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