Created
February 9, 2018 18:34
-
-
Save xfateless/90a172d3b3ad648881244031e2d631a5 to your computer and use it in GitHub Desktop.
Inheritance model implemented in JavaScript, a prototype-based language without classes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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