JSFiddle - React, Tailwind, and code Playground

by secretgspot

HTML

<h1>Prototype pattern | p1-a</h1>
<p>Same as previous but in old-way</p>

JavaScript

var vehiclePrototype = {
    init: function(carModel) {
        this.model = carModel;
    },
    getModel: function() {
         console.log('The model of this vehicle is..' + this.model);
    }
};


function vehicle(model) {
    function F() {};
    F.prototype = vehiclePrototype;
    var f = new F();
    f.init(model);
    return f;
}

var car = vehicle('Ford Escort');
car.getModel();