더북(TheBook)
class Person {
  name?: string;
  age?: number;
  married?: boolean;
  constructor();
  constructor(name: string, married: boolean);
  constructor(name: string, age: number, married: boolean);
  constructor(name?: string, age?: boolean | number, married?: boolean) {
    if (name) {
      this.name = name;
    }
    if (typeof age === 'boolean') {
      this.married = age;
    } else {
      this.age = age;
    }
    if (married) {
      this.married = married;
    }
  }
}
const person1 = new Person();
const person2 = new Person('nero', true);
const person3 = new Person('zero', 28, false);
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.