Exploring Prototypal Inheritance in Javascript


Objects can inherit properties and methods from a prototype.

Source Code

function Person(firstName, lastName) {
  this.firstName = firstName;
  this.lastName = lastName;
}
Person.prototype.fullName = function() {
  return `${this.firstName} ${this.lastName}`;
};
let person = new Person('John', 'Doe');
console.log(person.fullName()); // John Doe
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments