prototypes

by ellhn

JavaScript

function Employee(name) {
  this.name = name || "";
  this.department = "general";
}

function Manager(name, reports) {
  Employee.call(this, name);
  this.reports = reports;
}
Manager.prototype = Object.create(Employee.prototype);
Manager.prototype.constructor = Manager;

function WorkBee(name) {
  Employee.call(this, name);
  this.projectName = "";
}
WorkBee.prototype = Object.create(Employee.prototype);
WorkBee.prototype.constructor = WorkBee;

function SalesPerson(name, revenue) {
  WorkBee.call(this, name);
  this.department = "sales";
  this.projectName = "internal";
  this.revenue = revenue;
}
SalesPerson.prototype = Object.create(WorkBee.prototype);
SalesPerson.prototype.constructor = SalesPerson;

function SoftwareEngineer(name, techSkills) {
  WorkBee.call(this, name);
  this.department = "tech";
  this.projectName = "App-ComplyAdvantage";
  this.techSkills = techSkills;
}
SoftwareEngineer.prototype = Object.create(WorkBee.prototype);
SoftwareEngineer.prototype.constructor = SoftwareEngineer;


var John = new Manager("John Doe", [{name: "Q1", statistics: 2000}, {name: "Q2", statistics: 2002}]);
console.log(John.department); 
console.log(John.name) 
console.log(John.reports)


var Michael = new SalesPerson("Michael T", 2540);
console.log(Michael.department); 
console.log(Michael.name) 
console.log(Michael.projectName); 
console.log(Michael.revenue); 

var Joseph = new SoftwareEngineer("Joseph K. Ellis", ["Javascript", "HTML"], "App-ComplyAdvantage");
console.log(Joseph.department); 
console.log(Joseph.name) 
console.log(Joseph.projectName); 
console.log(Joseph.techSkills);