// prototype in javascript class
// To declare a class, you use the class keyword with the name of the class ("Rectangle" here).
class Rectangle {
constructor(w, h) {
this.w = w;
this.h = h;
}
}
// adds an 'area' method to the Rectangle class' as prototype
Rectangle.prototype.area = function () {
return this.w * this.h;
};
// create an instance of class
const findAreaOfRectangle = new Rectangle(8,3);
// invoke the area method
console.log(findAreaOfRectangle.area()); // Output: 24
A prototype simply does a method of that specific class, it is called a method because it is inside the class but after all it does a function