JSFiddle - React, Tailwind, and code Playground
JavaScript
(function( context ) {
function Employee( firstName, lastName ) {
this.name = firstName + ' ' + lastName;
}
Employee.prototype.saySomething = function() {
if( Math.round(Math.random()) ) {
sayHello.call(this);
} else {
sayGoodbye.call(this);
}
};
var sayHello = function() {
console.log('Hello from ' + this.name);
};
var sayGoodbye = function() {
console.log('Goodbye from ' + this.name);
};
context.Employee = Employee;
})(this);
(function( context ) {
'use strict';
function Boss( firstName, lastName, employees ) {
Employee.call(this, firstName, lastName);
this.employees = employees || [];
}
Boss.prototype = Object.create(Employee.prototype);
Boss.prototype.hire = function( employee ) {
this.employees.push(employee);
console.log(this.name + ' hired ' + employee.name);
};
Boss.prototype.fire = function( employee ) {
var index = this.employees.indexOf(employee);
if( index !== -1 ) {
this.employees.splice(index, 1);
console.log(this.name + ' fired ' + employee.name);
}
};
context.Boss = Boss;
})(this);
var john = new Employee('John', 'Doe');
var anna = new Employee('Anna', 'Simpson');
var bob = new Boss('Bob', 'Dylan', [ john, anna ]);
console.log(john, anna, bob);
bob.fire(anna);