Skip to content

Udemy/Ts/section5/68: static #44

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 52 commits into
base: UdemyTs
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
d105911
🌱: README을 수정
4BFC Aug 26, 2024
06270b7
🌱: README을 수정
4BFC Aug 26, 2024
5e69dee
🌱: README을 수정
4BFC Aug 29, 2024
d7c1360
🌱: README을 수정
4BFC Aug 29, 2024
978d932
🌱: README을 수정
4BFC Aug 29, 2024
859bffc
🌱: README을 수정
4BFC Aug 29, 2024
e09d95d
🌱: README을 수정
4BFC Aug 29, 2024
3255009
🌱: README을 수정
4BFC Aug 29, 2024
ab9b8db
🌱: README을 수정
4BFC Aug 29, 2024
5f0f9f9
🌱: README을 수정
4BFC Aug 29, 2024
daaeeed
🌱: README을 수정
4BFC Aug 29, 2024
c8ec455
🌱: README을 수정
4BFC Aug 30, 2024
e2a15fd
🌱: README을 수정
4BFC Aug 30, 2024
61dd842
🌱: README을 수정
4BFC Aug 30, 2024
bce5c89
🌱: README을 수정
4BFC Aug 30, 2024
ed8fa00
🌱: issue templates 생성
4BFC Aug 30, 2024
1559fa2
🌱: pr-template 생성
4BFC Aug 30, 2024
691897a
🌱: pr-template 수정
4BFC Aug 30, 2024
44ec035
🌱: pr-template 수정
4BFC Aug 30, 2024
3c3280b
🚩: udemy section2의 14번 강의를 듣고 실습을 했다.
4BFC Aug 31, 2024
cbf04eb
🔀: Merge branch 'UdemyTs'
4BFC Aug 31, 2024
0f07929
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Aug 31, 2024
757fb99
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Aug 31, 2024
7e8ac7d
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Aug 31, 2024
aa89074
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
79304fe
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
eb21a7f
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
cf56f00
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
7dec10d
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
28200e9
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 1, 2024
621e700
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 2, 2024
5f9833d
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 2, 2024
06d966b
Merge branch 'UdemyTs' of https://github.com/Programming-Contents-Lis…
4BFC Sep 20, 2024
6dbfd8c
🚩: interface를 학습하기 위해 클래스를 학습하고 실습해보았다.
4BFC Sep 20, 2024
a63622c
🚩: dist의 컴파일된 js를 확인하기 위해서 es5에서 es6로 ts.config 변경
4BFC Sep 20, 2024
e0853e1
🚩: es6에서 es5로 컴파일 target을 변경
4BFC Sep 20, 2024
fc69d9e
🚩: this를 사용해서 출력한 class 내 전역 name 프로퍼티 정상 출력
4BFC Sep 20, 2024
32a0146
🚩: this키워드를 다시 한번 객체로 감싼 복제 함수 할당 후 출력 undefined 결과 확인, this를 사용시 주의 사항
4BFC Sep 20, 2024
61ff6bf
🚩: undefined 재확인
4BFC Sep 20, 2024
8416f2b
🚩: 복제한 class의 함수를 사용 가능하게 하기 위한 방법과 에러 임시적인 해결 단, 똑같이 구현 불가능
4BFC Sep 20, 2024
cbdaa30
🚩: 배열 프로퍼티에 접근하는 두 가지 방식
4BFC Sep 21, 2024
24ebd7d
🚩: private 설정으로 employees[N]에 값을 할당할수 없다. error
4BFC Sep 21, 2024
c7ed403
🚩: 런타임과 컴파일 과정의 private 영향을 ts, js 파일에서 확인
4BFC Sep 21, 2024
01311f2
🚩: private를 일반적으로 constructor에서 사용하는 방법
4BFC Sep 21, 2024
263c777
🚩: constructor 생성자 내부에 따로 선언하지 않고 매개변수로 선언하는 간단한 방법
4BFC Sep 21, 2024
85531b3
🚩: readonly의 사용방법과 build된 app.js에서 확인할 수 있는 property 키워드 확인 및 실습
4BFC Sep 21, 2024
59c1851
🚩: 상속을 구현하고 실습해보았다.
4BFC Sep 23, 2024
eaa0d8b
🚩: getter와 setter 학습 및 실습
4BFC Sep 23, 2024
d430357
🚩: new키워드, 인스턴스를 사용하지 않고 바로 사용할 수 있는 class Math와 같이 코드를 구현해 볼 것
4BFC Sep 23, 2024
2fb018e
🚩: 정적인 static을 사용해서 new, 인스턴스를 사용하지 않고 바로 함수 호출 및 정적 변수 사용 예시
4BFC Sep 23, 2024
39a1432
🚩: 정적인 함수, 변수를 클래스, 생성자 내에서 정상적으로 동작하기 위한 조건과 한계 그리고 주의할 점
4BFC Sep 23, 2024
e05c219
Merge branch 'UdemyTs' into Udemy/Ts/section5/68
4BFC Sep 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 34 additions & 6 deletions src/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,19 @@ class Department {
// private id: string;
// private name: string;
private employees: string[] = [];
// readonly는 프로퍼티를 초기화한 후 수정할 수 없다. 즉, 한번 할당 되면 변경되면 안되는 고유 번호들을 설정할 때 readonly를 사용한다.
static fiscalYear = 2020;

constructor(private readonly id: string, public name: string) {
// this.id = id;
// this.name = n
// console.log(this.fiscalYear); //Error: static은 생성자가 필요 없기 때문에 Error 발생 즉, 생성자 함수, 클래스 내부에서는 static으로 선언된 정적인 함수, 변수는 재정의나 활용이 불가능
//만약 접근을 하려면 해당 클래스를 명시하고 접근을 해야 정상동작
console.log(Department.fiscalYear); //정상동작
}
static createEmployee(name: string) {
return { name: name };
}

describe(this: Department) {
console.log(`Department (${this.id}): ${this.name}`);
}
Expand All @@ -29,6 +37,21 @@ class ITDepartment extends Department {
this.admins = admins;
}
}
const accounting = new Department('1', 'Accounting');
const ITaccounting = new ITDepartment('2', ['Max']);

ITaccounting.addEmployee('Max');
ITaccounting.addEmployee('Manu');

// accounting.employees[2] = 'Anna';
ITaccounting.describe();
ITaccounting.printEmployeeInformation();

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

// console.log(NewAccounting.mostRecentReport); //report가 추가되지 않아서 Error
NewAccounting.setMostRecentReport = 'Year End Report';
NewAccounting.addReport('Something went wrong...');

class AccountingDepartment extends Department {
private lastReport: string;
Expand All @@ -45,13 +68,12 @@ class AccountingDepartment extends Department {
throw new Error('Please pass in a valid value!')
}
this.addReport(value);
this.lastReport = value; // 여기서 lastReport를 업데이트 그래야 lastReport가 비어있지 않기 때문에 정상적으로 동작을 한다.
this.lastReport = value;
}

constructor(id: string, private reports: string[]) {
super(id, 'Account');
//strictPropertyInitialization 활성화로 초기화 해줘야 함.
this.lastReport = reports[0] || ""; // 초기값을 할당 (reports가 비어있으면 빈 문자열)
this.lastReport = reports[0] || "";
}

addReport(text: string) {
Expand All @@ -62,9 +84,15 @@ class AccountingDepartment extends Department {
console.log(this.reports);
}
}

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

Math.pow(1, 2); //new, 인스턴스를 사용하지 않고 바로 사용할 수 있는 클래스 Math가 있다. 이와 같이 우리의 class도 구현 해볼 것이다. 방법은 static을 사용하는 것이다.

const employees1 = Department.createEmployee('Max'); //정적 메소드 불러오는 방식
console.log(employees1, Department.fiscalYear);

ITaccounting.addEmployee('Max');
ITaccounting.addEmployee('Manu');

Expand All @@ -74,10 +102,10 @@ ITaccounting.printEmployeeInformation();

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

// console.log(NewAccounting.mostRecentReport); //report가 추가되지 않아서 Error
// console.log(NewAccounting.mostRecentReport);
NewAccounting.setMostRecentReport = 'Year End Report';
NewAccounting.addReport('Something went wrong...');

console.log(NewAccounting.mostRecentReport); //report가 있어서 문제없이 출력
console.log(NewAccounting.mostRecentReport);

NewAccounting.printReports();