Constructor Pattern for Creating Objects

by SriSri M

JavaScript

function car(color,fuelType,price,city){
	this.color = color;
  this.fuelType = fuelType;
  this.price = price;
  this.city = city;
  
  this.showcar = function(){
  	console.log("This is Your Car's" +" "+ this.color);
  }
  this.cities = function(){
  	this.city.forEach(function (eachCity){
    	console.log('Available at'+" "+eachCity);
    }
)}
}

var swift = new car('blue','petrol',700000,['bangalore','chennai','mumbai']);
swift.showcar();
swift.cities();