Skip to content

Instantly share code, notes, and snippets.

@neerajkumar
Created June 7, 2018 18:35
Show Gist options
  • Save neerajkumar/d568dcf47e8af56099c5b3703275ae77 to your computer and use it in GitHub Desktop.
Save neerajkumar/d568dcf47e8af56099c5b3703275ae77 to your computer and use it in GitHub Desktop.
ES5 Inheritence - Javascript Solution
function Person(first_name, last_name) {
this.first_name = first_name;
this.last_name = last_name;
}
Person.prototype.getFullName = function() {
return this.first_name + ' ' + this.last_name;
}
function Student(studentId, first_name, last_name) {
this._super.call(this, first_name, last_name);
this.studentId = studentId;
}
Student.prototype._super = Person;
Student.prototype.getStudentInfo = function() {
return this.studentId + ', ' + this.first_name + ' ' + this.last_name;
}
var student = new Student(1, 'Neeraj', 'Kumar');
console.log(student.getStudentInfo());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment