JSFiddle - React, Tailwind, and code Playground
by andypotanin
JavaScript
function Vehicle( name, description ) {
this.name = name
this.description = description;
};
Vehicle.prototype.speed = 110;
Vehicle.prototype.color = 'black';
Vehicle.prototype.colors = [ 'black' ];
Vehicle.prototype.models = [];
Vehicle.prototype.lock = function Lock() {
Object.freeze( this );
}
var bmw = new Vehicle( 'BMW' );
var chevy = new Vehicle( 'Chevy' );
var delorean = new Vehicle( 'DeLorean', 'No longer manufactured.' );
// Prevent Changes to Delorean
delorean.lock();
// Chave the default color to green
bmw.__proto__.color = 'green';
// We now allow red and blue vehicles. Update prototype via the bmw
Object.getPrototypeOf( delorean ).colors.push( 'red', 'blue' );
// Set Colors Manually
bmw.color = 'white';
chevy.color = 'yellow';
delorean.color = 'brown';
bmw.models = [ '3-Series', 'M5', 'M6' ];
chevy.models = [ 'Tahoe', 'Malibu' ];
delorean.models = [ 'Time Machine' ];
console.log( 'bmw', bmw.speed, bmw.color, bmw.models, bmw.colors );
console.log( 'chevy', chevy.speed, chevy.color, chevy.models, chevy.colors );
console.log( 'delorean', delorean.speed, delorean.color, delorean.models, delorean.colors );