Skip to content

Instantly share code, notes, and snippets.

@cyb3rD
Created September 13, 2016 10:54
Show Gist options
  • Select an option

  • Save cyb3rD/444d646b5f71aa7925b8d87b920e3aac to your computer and use it in GitHub Desktop.

Select an option

Save cyb3rD/444d646b5f71aa7925b8d87b920e3aac to your computer and use it in GitHub Desktop.
Factory example
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