Skip to content

Instantly share code, notes, and snippets.

@OneCent01
Created February 9, 2018 18:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OneCent01/90a172d3b3ad648881244031e2d631a5 to your computer and use it in GitHub Desktop.
Save OneCent01/90a172d3b3ad648881244031e2d631a5 to your computer and use it in GitHub Desktop.
Inheritance model implemented in JavaScript, a prototype-based language without classes
function Employee() {
this.name = '';
this.dept = 'general';
}
function Manager() {
Employee.call(this);
this.reports = [];
}
Manager.prototype = Object.create(Employee.prototype);
function WorkerBee() {
Employee.call(this);
this.projects = [];
}
WorkerBee.prototype = Object.create(Employee.prototype);
function SalesPerson() {
WorkerBee.call(this);
this.dept = 'sales';
this.quota = 100;
}
SalesPerson.prototype = Object.create(WorkerBee.prototype);
function Engineer() {
WorkerBee.call(this);
this.dept = 'engineering';
this.machine = '';
}
Engineer.prototype = Object.create(WorkerBee.prototype);
// from https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Details_of_the_Object_Model
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment