// 함수 - 명시적 this

interface Cat {
    name : string
    age : number
}

const cat : Cat = {
    name: 'Lucy',
    age: 3
}

// 일반 함수 내부에서 this 위치는 호출 위치에서 정의한다.
// 'this' implicitly has type 'any' because it does not have a type annotation.(2683)
// this를 명시해준다. this의 타입을 명시해줌
// 매개변수처럼 보이지만, this의 타입을 명시해주는 것이라고 생각하는게 좋음
function hello(this:Cat, message: string) {
    console.log(`hello ${this.name}, ${message}`)
}

// 콜 메서드를 통해 호출되고 있다.
hello.call(cat, 'You are pretty awesome!')

참조