Command Pattern
by Steven Senkus
JavaScript
(function () {
var CarManager = {
requestInfo: function (model, id) {
console.log('The information for ' + model + ' with ID ' + id + ' is foobar');
},
buyVehicle: function (model, id) {
console.log("You have successfully purchased Item " + id + ', a ' + model);
},
arrangeViewing: function (model, id) {
console.log('You have successfully booked a viewing of ' + model + ' ( ' + id + ' ) ');
}
};
CarManager.execute = function (name) {
return CarManager[name] && CarManager[name].apply(CarManager, Array.prototype.slice.call(arguments, 1));
};
CarManager.execute('arrangeViewing', 'Ferrari', '14523');
CarManager.execute('requestInfo', 'Ford Mondeo', '15523');
CarManager.execute('requestInfo', 'Ford Escort', '24523');
CarManager.execute('buyVehicle', 'Ford Escort', '54523');
})();