Create prototype example

This commit is contained in:
LSvekis
2021-09-04 12:59:54 -04:00
committed by GitHub
parent 21691a9611
commit 0189d40676
+18
View File
@@ -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());
})