From 0189d40676cc0ee63c8a7f195f514c5ce40bb446 Mon Sep 17 00:00:00 2001 From: LSvekis Date: Sat, 4 Sep 2021 12:59:54 -0400 Subject: [PATCH] Create prototype example --- chapter7/prototype example | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 chapter7/prototype example diff --git a/chapter7/prototype example b/chapter7/prototype example new file mode 100644 index 0000000..f2c9ae5 --- /dev/null +++ b/chapter7/prototype example @@ -0,0 +1,18 @@ +class Employee { + constructor(first, last, years) { + this.first = first; + this.last = last; + this.years = years; + } +} +const person1 = new Employee("Laurence", "Svekis", 10); +const person2 = new Employee("Maaike", "van Putten", 5); +const workers = [person1, person2]; + +Employee.prototype.details = function(){ + return this.first + " " + this.last + " has worked here " + this.years + " years" +} + +workers.forEach((person) => { + console.log(person.details()); +})