Skip to content

Instantly share code, notes, and snippets.

@droidjahangir
Created September 16, 2021 04:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save droidjahangir/1c92720bd41e61035c73b55d428138a4 to your computer and use it in GitHub Desktop.
Save droidjahangir/1c92720bd41e61035c73b55d428138a4 to your computer and use it in GitHub Desktop.
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