Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save hafeez-syed/e0e888f7776ecb52a839f6e5322da2bd to your computer and use it in GitHub Desktop.
Save hafeez-syed/e0e888f7776ecb52a839f6e5322da2bd to your computer and use it in GitHub Desktop.
'use strict';
function Person(first_name, last_name) {
this.first_name = first_name;
this.last_name = last_name;
};
Person.prototype.full_name = function() {
return this.first_name + ' ' + this.last_name;
};
var person = new Person('Hafeez', 'Syed');
console.log(person.full_name());
function Professional(honorific, first_name, last_name) {
Person.call(this, first_name, last_name);
this.honorific = honorific;
}
// Add `Inheritance` to make full_name() accessible to Professional
Professional.prototype = Object.create(Person.prototype);
Professional.prototype.professional_name = function() {
return this.honorific + ' ' + this.first_name + ' ' + this.last_name;
};
var profess = new Professional('Dr.', 'Hafeez', 'Syed');
console.log(profess.professional_name());
console.log(profess.full_name());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment