Posts

Showing posts with the label nodejs javascript oops inheritance

Inheritance in Javascript

Inheritance in Javascript Inheritance is when an object or class is based on another object (prototypal inheritance) or class (class-based inheritance), using the same implementation. function Person(name, age, gender, interests) {   this.name = name   this.age = age;   this.gender = gender;   this.interests = interests;   this.getName = function() {     return this.name;   } }; Person.prototype.getAge = function() {   return this.age; } /** Teacher inherit properties from the person class. Person.call(this, name, age, gender, interests ) after .call() properties are inherited in teacher class. */ function Teacher(name, age, gender, interests, subject) {   Person.call(this, name, age, gender, interests)   // Vehicle.call(this)   this.subject = subject;   this.getSubject = function() {     return this.subject;   }   this.getName = function(...