JavaScript OOP에서 클래스와 모듈

일반적으로 각 클래스는 별도의 모듈에 위치시킵니다. 이때 모듈 파일의 이름은 저장된 클래스의 이름과 일치해야 합니다. 클래스 User를 해당 파일에 넣어 봅시다:

User.jsexport default class User {
  #name;
  
  constructor(name) {
    this.#name = name;
  }
  getName() {
    return this.#name;
  }
}

파일 index.js에서 클래스를 임포트합니다:

index.jsimport User from './User.js';

이제 이 파일에서 클래스를 사용할 수 있습니다:

index.jslet user = new User('john');
Задание 1

클래스 Employee를 별도의 파일에 배치하세요.

Задание 2

파일 index.js에서 이 클래스의 객체를 생성하세요.