TIL 2021-06-02 (Typescript 로 블록체인 만들기 -2)

nyongho·2021년 6월 3일
0

오늘 배운 내용

목록 보기
27/40

TIL


1편에서 다뤘던 인터페이스 대신 클래스를 이용할 수 있다.

 class Human {
     public name: string;
     public age: number;
     public gender: string;
     constructor(name: string, age:number, gender:string) {
         this.name = name;
         this.age  = age;
         this.gender = gender;
     }
 }

const yongho = new Human("Yongho", 22, "Male")

const sayHi = (person:Human):string => {
    return `Hello ${person.name}, you are ${person.age}, your gender is ${person.gender}!`
}

console.log(sayHi(yongho))
profile
두 줄 소개

0개의 댓글