Last active
August 29, 2015 14:12
-
-
Save almonk/3898e7348d0f49ea8f84 to your computer and use it in GitHub Desktop.
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 car() { | |
return { | |
start: function() { | |
console.log("Engine on."); | |
}, | |
accelerate: function() { | |
console.log("Let's go!"); | |
} | |
}; | |
} | |
function roadster(brand) { | |
var brand = brand; | |
var baseCar = car(); | |
return { | |
start: function() { | |
return baseCar.start(); | |
}, | |
accelerate: function() { | |
return baseCar.accelerate(); | |
}, | |
setBrand: function(name) { | |
brand = name; | |
}, | |
getBrand: function() { | |
console.log(brand); | |
} | |
}; | |
} | |
var myCar = roadster("Porsche") | |
myCar.start() // "Engine on." | |
myCar.getBrand() // "Porsche" | |
myCar.setBrand("Jaguar") | |
myCar.getBrand() // "Jaguar" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment