UNPKG

libperson

Version:

Data structure to represent humans

29 lines (26 loc) 592 B
const Vegetable = require("libvegetable"); const Fruit = require("jsfruit"); class PersonNotHungryError extends Error {} module.exports = class Person extends Vegetable { constructor(name) { super(name); this.hungry = true; } feed() { if (this.hungry) { this.hungry = false; setTimeout( () => { this.hungry = true; }, 1_000 * 60 * 60 * 4, ); } else throw new PersonNotHungryError( this.name + " is not hungry and cannot be fed", ); } greet() { return new Fruit(this.name).greet(); } };