File tree Expand file tree Collapse file tree 1 file changed +6
-25
lines changed
Expand file tree Collapse file tree 1 file changed +6
-25
lines changed Original file line number Diff line number Diff line change 1- import { Benz , Car } from "./utils/data.interface" ;
2-
3- //클래스 : 객체의 행동과 구조를 정의하기에 '='을 사용한다.
4- class Bmw implements Car {
5- color = '' ;
6- constructor ( color : string ) {
1+ class Car {
2+ // color: string; //-> 생성자에서 this를 사용하기 위해서는 사용될 변수 프로퍼티를 먼제 선언 해야한다.
3+ // 하지만 프로퍼티를 선언하지 않고 사용하는 방법이 public과 readonly를 해당 매개변수에 지정해주면 된다.
4+ constructor ( readonly color : string ) { //public
75 this . color = color ;
86 }
9- wheels = 4 ;
107 start ( ) {
11- console . log ( 'go..' ) ;
8+ console . log ( "start" ) ;
129 }
1310}
1411
15- const b = new Bmw ( 'white' ) ;
16- console . log ( b ) ;
17- b . start ( ) ;
18-
19- //extends
20- //객체 리터럴 : 객체를 리터럴해야하기 때문에 key, value 값으로 정의하게 되고 클래스와 달리 '='를 사용해야 한다.
21- const benz : Benz = {
22- color : 'black' ,
23- wheels : 4 ,
24- start ( ) {
25- console . log ( 'go...' ) ;
26- } ,
27- door : 5 ,
28- stop ( ) {
29- console . log ( 'stop...' ) ;
30- } ,
31- }
12+ const bmw = new Car ( "red" ) ;
You can’t perform that action at this time.
0 commit comments