Simplified Inheritance in JS (ES5 way)

function Person(fName, lName) {
this.firstName = fName;
this.lastName = lName;
}
var p1 = new Person('Laxmikant','Dange');
Person.prototype.getFullName = function () {
return this.firstName + ' ' + this.lastName;
}
p1.hasOwnProperty('firstName');  // Returns true
p1.hasOwnProperty('lastName'); // Returns true
p1.hasOwnProperty('getFullName') // Returns false
function Person(fName, lName) {
this.firstName = fName;
this.lastName = lName;
}
Person.prototype.getFullName = function () {
return this.firstName + ' ' + this.lastName;
}
function Employee(fName, lName, eId) {
Person.call(this, fName, lName);
this.empId = eId;
}
Employee.prototype = Object.create(Person.prototype);
Employee.prototype.constructor = Employee;
Employee.prototype.getEmpInfo = function () {
return [this.empId, this.firstName, this.lastName];
}
var e1 = new Employee('Jhon', 'Doe', 10);
e1.getFullName();
e1.getEmpInfo();

--

--

--

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Laxmikant Dange

Laxmikant Dange

More from Medium

Singleton and Factory Design patterns in JavaScript

JavaScript Development (03) — handle the undefined

JavaScript and Version Controlling

Use Chrome devtools understanding Closure .