JSFiddle - React, Tailwind, and code Playground

by Douglas Enas

JavaScript

var Car = function() {
    this.doors = 2;
}

Car.prototype = (function() {
    hotWire = function() {
        // Private code *with* access to public properties through 'this'
        alert(this.drive() + this.doors); // Alerts 'Vroom!'
        testme.call(this);
    }, testme = function() {
        alert(this.doors);
    }

    return {
        steal: function() {
            hotWire.call(this); // Call a private method
        },
        drive: function() {
            return 'Vroom!';
        }
    };
})();


var c1 = new Car();

c1.steal();