Nest.js에서 this 생략되는 이유

Nest.js에서 this 생략되는 이유

카테고리
Nest.js
날짜
2024년 06월 14일
작성자
JeongjungsikJeongjungsik
태그
backend
import { Controller, Get } from '@nestjs/common'; import { AppService } from './app.service'; @Controller() export class AppController { constructor(private readonly appService: AppService) {} @Get() getHello(): string { return this.appService.getHello(); } }
위의 코드에서 this.appService 가 선언되어있지 않는데, 이유는
public , private , protected , readonly 이 중에 한개라도 있으면 생략 가능하기 때문이다.
 
원래는 다음과 같은 형식으로 되어있어야 함
class Monster { number; constructor(number) { this.number= number } }

댓글

guest