Skip to content

Commit a9004f1

Browse files
authored
๐Ÿ”€: Udemy/Ts/section5/67: getter/setter (#43)
* ๐ŸŒฑ: 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 ํ‚ค์›Œ๋“œ ํ™•์ธ ๋ฐ ์‹ค์Šต * ๐Ÿšฉ: ์ƒ์†์„ ๊ตฌํ˜„ํ•˜๊ณ  ์‹ค์Šตํ•ด๋ณด์•˜๋‹ค. * ๐Ÿšฉ: getter์™€ setter ํ•™์Šต ๋ฐ ์‹ค์Šต
1 parent 26fa393 commit a9004f1

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

โ€Žsrc/app.ts

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,43 @@ class Department {
1515
// this.id = '2'; // readonly์ด๊ธฐ ๋•Œ๋ฌธ์— error๊ฐ€ ๋ฐœ์ƒํ•œ๋‹ค.
1616
this.employees.push(employee);
1717
}
18+
19+
printEmployeeInformation() {
20+
console.log(this.employees.length);
21+
console.log(this.employees);
22+
}
1823
}
1924

2025
class ITDepartment extends Department {
2126
admins: string[];
22-
constructor(id: string, public admin: string[]) {
27+
constructor(id: string, admins: string[]) {
2328
super(id, 'IT');
24-
this.admins = admin;
29+
this.admins = admins;
2530
}
2631
}
2732

2833
class AccountingDepartment extends Department {
34+
private lastReport: string;
35+
36+
get mostRecentReport() {
37+
if (this.lastReport) {
38+
return this.lastReport;
39+
}
40+
throw new Error('No report found.');
41+
}
42+
43+
set setMostRecentReport(value: string) {
44+
if (!value) {
45+
throw new Error('Please pass in a valid value!')
46+
}
47+
this.addReport(value);
48+
this.lastReport = value; // ์—ฌ๊ธฐ์„œ lastReport๋ฅผ ์—…๋ฐ์ดํŠธ ๊ทธ๋ž˜์•ผ lastReport๊ฐ€ ๋น„์–ด์žˆ์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ์ •์ƒ์ ์œผ๋กœ ๋™์ž‘์„ ํ•œ๋‹ค.
49+
}
50+
2951
constructor(id: string, private reports: string[]) {
3052
super(id, 'Account');
53+
//strictPropertyInitialization ํ™œ์„ฑํ™”๋กœ ์ดˆ๊ธฐํ™” ํ•ด์ค˜์•ผ ํ•จ.
54+
this.lastReport = reports[0] || ""; // ์ดˆ๊ธฐ๊ฐ’์„ ํ• ๋‹น (reports๊ฐ€ ๋น„์–ด์žˆ์œผ๋ฉด ๋นˆ ๋ฌธ์ž์—ด)
3155
}
3256

3357
addReport(text: string) {
@@ -38,7 +62,6 @@ class AccountingDepartment extends Department {
3862
console.log(this.reports);
3963
}
4064
}
41-
4265
const accounting = new Department('1', 'Accounting');
4366
const ITaccounting = new ITDepartment('2', ['Max']);
4467

@@ -51,6 +74,10 @@ ITaccounting.printEmployeeInformation();
5174

5275
const NewAccounting = new AccountingDepartment('d2', []);
5376

77+
// console.log(NewAccounting.mostRecentReport); //report๊ฐ€ ์ถ”๊ฐ€๋˜์ง€ ์•Š์•„์„œ Error
78+
NewAccounting.setMostRecentReport = 'Year End Report';
5479
NewAccounting.addReport('Something went wrong...');
5580

81+
console.log(NewAccounting.mostRecentReport); //report๊ฐ€ ์žˆ์–ด์„œ ๋ฌธ์ œ์—†์ด ์ถœ๋ ฅ
82+
5683
NewAccounting.printReports();

0 commit comments

Comments
ย (0)