Life Developer
인생 개발자
[typescript]class - 자식 생성자는 super를 꼭 가져야함

class Person{

    constructor(protected _name:stringprotected _age:number){

 

    }

 

    hello():void {

        console.log(this._name);

    }

}

 

const person : Person = new Person('kim',30);

person.hello();



class Child extends Person{

    constructor(){

        super('man',300);

    }

}

 

const child:Child = new Child();

 

child.hello();

'Developer' 카테고리의 다른 글

[typescript]class - readonly  (0) 2020.10.01
[typescript]class - getter와 setter  (0) 2020.10.01
[typescript]class - class안에 생성자의 private 변수  (0) 2020.10.01
[typescript]class - protected  (0) 2020.10.01
[typescript]class - private  (0) 2020.10.01
  Comments,     Trackbacks