js - OOPS

// Object literal for creating object

let car = {
  maruti : "Maruti 800",
  topSpeed : 80,
  run : function(){
    console.log("car is running")
  }
}
console.log(car)

// Contrucutor - templates used for creating objects with the help of "new".
// Eg : new Date()

// Creating a construcotr for cars:

function generalCar(name, speed) {
  this.name = name;
  this.topSpeed = speed;
  this.run = function () {
    console.log(`${this.name} is running`);
  };
  this.analyze = function(){
    console.log(`car comparison`)
  }
}

car1 = new generalCar("nissan",80)
car2 = new generalCar("mercedes", 180);
console.log(typeof car1);
console.log(car1)
console.log(car2);


0 Comments