Created
September 16, 2021 04:33
-
-
Save droidjahangir/1c92720bd41e61035c73b55d428138a4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Department { | |
name: string; | |
employees: string[] = []; | |
constructor(n: string) { | |
this.name = n; | |
} | |
addEmployee(employee: string) { | |
// + validation here (etc.) | |
this.employees.push(employee); | |
} | |
printEmployeeInformation() { | |
console.log(this.employees.length); | |
console.log(this.employees); | |
} | |
} | |
const accounting = new Department('accounting'); | |
accounting.addEmployee('Max'); | |
accounting.addEmployee('Manu'); | |
accounting.employees[2] = 'Anna'; // WE DON'T WANT THAT, because we want to use addEmployee (for the validation...) | |
accounting.printEmployeeInformation(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment