Prototype Pattern & Classes

				
					let Study = function (course, level) {
  this.course = course;
  this.level = level;

  this.courseLevel = function () {
    console.log(this.course + " is for " + this.level);
  };
  
  this.Enquiry = function () {
  console.log("I just want to have enquiry. I am yet to think of enrolling...");
};
};

let study1 = new Study("Javascript", "Beginners");
let study2 = new Study("Advanced Javascript", "Professionals");
let study3 = new Study("ES new concepts", "Proficients");
let study4 = new Study("Typescript", "Beginners");

study1.courseLevel();
study2.courseLevel();
study3.courseLevel();
study4.Enquiry();

//Output
// Javascript is for Beginners
// Advanced Javascript is for Professionals
// ES new concepts is for Proficient

				
			
				
					
let Study = function (course, level) {
  this.course = course;
  this.level = level;
};

Study.prototype.courseLevel = function () {
  console.log(this.course + " is for " + this.level);
};

Study.prototype.enquiry = function () {
  console.log("I just want to have enquiry. I am yet to think of enrolling...");
};

let study1 = new Study("Javascript", "Beginners");
let study2 = new Study("Advanced Javascript", "Professionals");
let study3 = new Study("ES new concepts", "Proficients");
let study4 = new Study("Typescript", "Beginners");

study1.courseLevel();
study2.courseLevel();
study3.courseLevel();
study4.enquiry();

//Output
// Javascript is for Beginners
// Advanced Javascript is for Professionals
// ES new concepts is for Proficient

				
			
				
					//**IN ECMASCRIPT WE NOW USE CLASSES INSTEAD OF FUNCTIONS.... */

class Study {
  constructor(course, level) {
    this.course = course;
    this.level = level;
  }
  courseLevel = function () {
    console.log(this.course + " is for " + this.level);
  };

  enquiry = function () {
    console.log("I just want to have enquiry. I am yet to think of enrolling...");
  };
}

let study1 = new Study("Javascript", "Beginners");
let study2 = new Study("Advanced Javascript", "Professionals");
let study3 = new Study("ES new concepts", "Proficients");
let study4 = new Study("Typescript", "Beginners");

study1.courseLevel();
study2.courseLevel();
study3.courseLevel();
study4.enquiry();

//Output
// Javascript is for Beginners
// Advanced Javascript is for Professionals
// ES new concepts is for Proficient
//I just want to have enquiry. I am yet to think of enrolling...

				
			

Leave a Comment