Created
September 13, 2016 10:54
-
-
Save cyb3rD/444d646b5f71aa7925b8d87b920e3aac to your computer and use it in GitHub Desktop.
Factory example
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 createVehicle(vehicleType){ | |
| return function(brand) { | |
| if (vehicleType === 'Car') { | |
| console.log('Achieve New Car! Brand:' + brand); | |
| } | |
| if (vehicleType === 'Truck') { | |
| console.log('Achieve New Truck! Brand:' + brand); | |
| } | |
| } | |
| } | |
| // New execution context each time function runs | |
| var myCar = createVehicle('Car'); | |
| var myTruck = createVehicle('Truck'); | |
| myCar('Volvo'); | |
| myTruck('Renault'); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment