JSFiddle - React, Tailwind, and code Playground

by secretgspot

HTML

<h1>Command pattern</h1>

JavaScript

$(function() {

    var CarManager = {

        /* request information */
        requestInfo: function(model, id) {
            return 'The information for ' + model + ' with ID ' + id + ' is foobar';
        },

        /* purchase the car */
        buyVehicle: function(model, id) {
            return 'You have successfully purchased Item ' + id + ', a ' + model;
        },

        /* arrange a viewing */
        arrangeViewing: function(model, id) {
            return 'You have successfully booked a viewing of ' + model + ' ( ' + id + ' ) ';
        }

    };

})();

    CarManager.execute = function(command){
      return CarManager[command.request](command.model,command.carID);
    };

CarManager.execute({request: "arrangeViewing", model: 'Ferrari', carID: '145523'});  
CarManager.execute({request: "requestInfo", model: 'Ford Mondeo', carID: '543434'});    
CarManager.execute({request: "requestInfo", model: 'Ford Escort', carID: '543434'});    
CarManager.execute({request: "buyVehicle", model: 'Ford Escort', carID: '543434'});