February 2018
Intermediate to advanced
298 pages
8h 22m
English
All the methods in the body of the class are added to the prototype property of the class. The prototype property is the prototype of the objects created using class.
Here is an example that shows how to add methods to the prototype property of a class:
class Person { constructor(name, age) { this.name = name; this.age = age; } printProfile() { console.log("Name is: " + this.name + " and Age is: " + this.age); } } const p = new Person("Eden", 12);p.printProfile(); console.log("printProfile" in p.__proto__); console.log("printProfile" in Person.prototype);
The output is as follows:
Name is: Eden and Age is: 12truetrue
Here, we can see that the printProfile method was added to the prototype property of the class ...
Read now
Unlock full access