Skip to content

Commit 26fa393

Browse files
authored
๐Ÿ”€: Udemy/ts/section5/65: inheritance(์ƒ์†) (#41)
* ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: README์„ ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: issue templates ์ƒ์„ฑ Github์—์„œ ์ž‘์„ฑํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: pr-template ์ƒ์„ฑ Github์—์„œ ์ž‘์„ฑํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: pr-template ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐ŸŒฑ: pr-template ์ˆ˜์ • Github์—์„œ ์ˆ˜์ •ํ•œ ์ปค๋ฐ‹์ž…๋‹ˆ๋‹ค. * ๐Ÿšฉ: udemy section2์˜ 14๋ฒˆ ๊ฐ•์˜๋ฅผ ๋“ฃ๊ณ  ์‹ค์Šต์„ ํ–ˆ๋‹ค. * ๐Ÿšฉ: interface๋ฅผ ํ•™์Šตํ•˜๊ธฐ ์œ„ํ•ด ํด๋ž˜์Šค๋ฅผ ํ•™์Šตํ•˜๊ณ  ์‹ค์Šตํ•ด๋ณด์•˜๋‹ค. * ๐Ÿšฉ: dist์˜ ์ปดํŒŒ์ผ๋œ js๋ฅผ ํ™•์ธํ•˜๊ธฐ ์œ„ํ•ด์„œ es5์—์„œ es6๋กœ ts.config ๋ณ€๊ฒฝ * ๐Ÿšฉ: es6์—์„œ es5๋กœ ์ปดํŒŒ์ผ target์„ ๋ณ€๊ฒฝ * ๐Ÿšฉ: this๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ถœ๋ ฅํ•œ class ๋‚ด ์ „์—ญ name ํ”„๋กœํผํ‹ฐ ์ •์ƒ ์ถœ๋ ฅ * ๐Ÿšฉ: thisํ‚ค์›Œ๋“œ๋ฅผ ๋‹ค์‹œ ํ•œ๋ฒˆ ๊ฐ์ฒด๋กœ ๊ฐ์‹ผ ๋ณต์ œ ํ•จ์ˆ˜ ํ• ๋‹น ํ›„ ์ถœ๋ ฅ undefined ๊ฒฐ๊ณผ ํ™•์ธ, this๋ฅผ ์‚ฌ์šฉ์‹œ ์ฃผ์˜ ์‚ฌํ•ญ * ๐Ÿšฉ: undefined ์žฌํ™•์ธ * ๐Ÿšฉ: ๋ณต์ œํ•œ class์˜ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•˜๊ฒŒ ํ•˜๊ธฐ ์œ„ํ•œ ๋ฐฉ๋ฒ•๊ณผ ์—๋Ÿฌ ์ž„์‹œ์ ์ธ ํ•ด๊ฒฐ ๋‹จ, ๋˜‘๊ฐ™์ด ๊ตฌํ˜„ ๋ถˆ๊ฐ€๋Šฅ * ๐Ÿšฉ: ๋ฐฐ์—ด ํ”„๋กœํผํ‹ฐ์— ์ ‘๊ทผํ•˜๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ์‹ * ๐Ÿšฉ: private ์„ค์ •์œผ๋กœ employees[N]์— ๊ฐ’์„ ํ• ๋‹นํ• ์ˆ˜ ์—†๋‹ค. error * ๐Ÿšฉ: ๋Ÿฐํƒ€์ž„๊ณผ ์ปดํŒŒ์ผ ๊ณผ์ •์˜ private ์˜ํ–ฅ์„ ts, js ํŒŒ์ผ์—์„œ ํ™•์ธ * ๐Ÿšฉ: private๋ฅผ ์ผ๋ฐ˜์ ์œผ๋กœ constructor์—์„œ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ• * ๐Ÿšฉ: constructor ์ƒ์„ฑ์ž ๋‚ด๋ถ€์— ๋”ฐ๋กœ ์„ ์–ธํ•˜์ง€ ์•Š๊ณ  ๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์„ ์–ธํ•˜๋Š” ๊ฐ„๋‹จํ•œ ๋ฐฉ๋ฒ• * ๐Ÿšฉ: readonly์˜ ์‚ฌ์šฉ๋ฐฉ๋ฒ•๊ณผ build๋œ app.js์—์„œ ํ™•์ธํ•  ์ˆ˜ ์žˆ๋Š” property ํ‚ค์›Œ๋“œ ํ™•์ธ ๋ฐ ์‹ค์Šต * ๐Ÿšฉ: ์ƒ์†์„ ๊ตฌํ˜„ํ•˜๊ณ  ์‹ค์Šตํ•ด๋ณด์•˜๋‹ค.
1 parent 26a8d1f commit 26fa393

File tree

2 files changed

+63
-7
lines changed

2 files changed

+63
-7
lines changed

โ€Ždist/app.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
"use strict";
2+
var Department = /** @class */ (function () {
3+
// readonly๋Š” ํ”„๋กœํผํ‹ฐ๋ฅผ ์ดˆ๊ธฐํ™”ํ•œ ํ›„ ์ˆ˜์ •ํ•  ์ˆ˜ ์—†๋‹ค. ์ฆ‰, ํ•œ๋ฒˆ ํ• ๋‹น ๋˜๋ฉด ๋ณ€๊ฒฝ๋˜๋ฉด ์•ˆ๋˜๋Š” ๊ณ ์œ  ๋ฒˆํ˜ธ๋“ค์„ ์„ค์ •ํ•  ๋•Œ readonly๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.
4+
function Department(id, name) {
5+
this.id = id;
6+
this.name = name;
7+
// private id: string;
8+
// private name: string;
9+
this.employees = [];
10+
// this.id = id;
11+
// this.name = n
12+
}
13+
Department.prototype.describe = function () {
14+
console.log("Department (".concat(this.id, "): ").concat(this.name));
15+
};
16+
Department.prototype.addEmployee = function (employee) {
17+
// this.id = '2'; // readonly์ด๊ธฐ ๋•Œ๋ฌธ์— error๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
18+
this.employees.push(employee);
19+
};
20+
Department.prototype.printEmployeeInformation = function () {
21+
console.log(this.employees.length);
22+
console.log(this.employees);
23+
};
24+
return Department;
25+
}());
26+
var accounting = new Department('1', 'Accounting');
27+
accounting.addEmployee('Max');
28+
accounting.addEmployee('Manu');
29+
// accounting.employees[2] = 'Anna';
30+
accounting.describe();
31+
accounting.printEmployeeInformation();

โ€Žsrc/app.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,42 @@ class Department {
1515
// this.id = '2'; // readonly์ด๊ธฐ ๋•Œ๋ฌธ์— error๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
1616
this.employees.push(employee);
1717
}
18-
printEmployeeInformation() {
19-
console.log(this.employees.length);
20-
console.log(this.employees);
18+
}
19+
20+
class ITDepartment extends Department {
21+
admins: string[];
22+
constructor(id: string, public admin: string[]) {
23+
super(id, 'IT');
24+
this.admins = admin;
25+
}
26+
}
27+
28+
class AccountingDepartment extends Department {
29+
constructor(id: string, private reports: string[]) {
30+
super(id, 'Account');
31+
}
32+
33+
addReport(text: string) {
34+
this.reports.push(text);
35+
}
36+
37+
printReports() {
38+
console.log(this.reports);
2139
}
2240
}
2341

2442
const accounting = new Department('1', 'Accounting');
43+
const ITaccounting = new ITDepartment('2', ['Max']);
2544

26-
accounting.addEmployee('Max');
27-
accounting.addEmployee('Manu');
45+
ITaccounting.addEmployee('Max');
46+
ITaccounting.addEmployee('Manu');
2847

2948
// accounting.employees[2] = 'Anna';
30-
accounting.describe();
31-
accounting.printEmployeeInformation();
49+
ITaccounting.describe();
50+
ITaccounting.printEmployeeInformation();
51+
52+
const NewAccounting = new AccountingDepartment('d2', []);
53+
54+
NewAccounting.addReport('Something went wrong...');
55+
56+
NewAccounting.printReports();

0 commit comments

Comments
ย (0)