Prototype

Javascript prototype experiment

by Sajidur Rahman

HTML

<div id='result'>
    
</div>

JavaScript

'use strict'

function Vehicle(name){
	this.name = name;
}

function Car(name, price){
	Vehicle.call(this, name); // Call super class with argument
  this.price = price;
}

Car.prototype = Object.create(Vehicle.prototype);
Car.prototype.constructor = Car;

var car = new Car('Porche', 50000);

Vehicle.prototype.color = 'red';

document.getElementById('result').innerHTML = car.name + ' ' + '$' + car.price + ' Color:' + car.color;



console.log(Vehicle.prototype, Car.prototype);