Skip to content

Latest commit

 

History

History
19 lines (16 loc) · 499 Bytes

File metadata and controls

19 lines (16 loc) · 499 Bytes
/**
 * Demonstration of Prototypal Inheritance using javascript functions
 */

const { EventEmitter } = require('events');

function Person(name) {
  EventEmitter.call(this);
  this.name = name;
}
Person.prototype = Object.create(EventEmitter.prototype);

const benjaminFranklin = new Person('Benjamin Franklin');
benjaminFranklin.on('speak', function message(msg) {
  console.log(`${this.name} says ${msg}`);
});
benjaminFranklin.emit('speak', 'You may delay, but time will not');