diff --git a/dist/app.js b/dist/app.js index e69de29..fa5b1c1 100644 --- a/dist/app.js +++ b/dist/app.js @@ -0,0 +1,31 @@ +"use strict"; +var Department = /** @class */ (function () { + // readonly는 프로퍼티를 초기화한 후 수정할 수 없다. 즉, 한번 할당 되면 변경되면 안되는 고유 번호들을 설정할 때 readonly를 사용한다. + function Department(id, name) { + this.id = id; + this.name = name; + // private id: string; + // private name: string; + this.employees = []; + // this.id = id; + // this.name = n + } + Department.prototype.describe = function () { + console.log("Department (".concat(this.id, "): ").concat(this.name)); + }; + Department.prototype.addEmployee = function (employee) { + // this.id = '2'; // readonly이기 때문에 error가 발생한다. + this.employees.push(employee); + }; + Department.prototype.printEmployeeInformation = function () { + console.log(this.employees.length); + console.log(this.employees); + }; + return Department; +}()); +var accounting = new Department('1', 'Accounting'); +accounting.addEmployee('Max'); +accounting.addEmployee('Manu'); +// accounting.employees[2] = 'Anna'; +accounting.describe(); +accounting.printEmployeeInformation(); diff --git a/src/app.ts b/src/app.ts index 4ab88f1..9bcceb1 100644 --- a/src/app.ts +++ b/src/app.ts @@ -15,17 +15,42 @@ class Department { // this.id = '2'; // readonly이기 때문에 error가 발생한다. this.employees.push(employee); } - printEmployeeInformation() { - console.log(this.employees.length); - console.log(this.employees); +} + +class ITDepartment extends Department { + admins: string[]; + constructor(id: string, public admin: string[]) { + super(id, 'IT'); + this.admins = admin; + } +} + +class AccountingDepartment extends Department { + constructor(id: string, private reports: string[]) { + super(id, 'Account'); + } + + addReport(text: string) { + this.reports.push(text); + } + + printReports() { + console.log(this.reports); } } const accounting = new Department('1', 'Accounting'); +const ITaccounting = new ITDepartment('2', ['Max']); -accounting.addEmployee('Max'); -accounting.addEmployee('Manu'); +ITaccounting.addEmployee('Max'); +ITaccounting.addEmployee('Manu'); // accounting.employees[2] = 'Anna'; -accounting.describe(); -accounting.printEmployeeInformation(); +ITaccounting.describe(); +ITaccounting.printEmployeeInformation(); + +const NewAccounting = new AccountingDepartment('d2', []); + +NewAccounting.addReport('Something went wrong...'); + +NewAccounting.printReports();