[Do it! 타입스크립트 프로그래밍#7]
콜백함수
매개변수 형태로 동작하는 함수를 콜백 함수 (callback function)라고 합니다.
const f =(callback: () => void): void => callback()
프레임워크 API 구현에 유용한 콜백함수
export type Person = {name: string , age: number}
export const makePerson = (name: string, age: number = 10):
Person => {
const person = {name: name , age:age}
return person
}
console.log(makePerson('Jack')) // {name: 'Jack', age: 10}
consoel.log(makePerson('Jane',33)) // {name: 'Jane',age:33}
클래스 메서드
function 함수와 this 키워드
메서드란?
export class A {
value: number = 1
method: () => void = function(): void {
console.log(value: ${this.value}
)
}
}