Life Developer
인생 개발자
[typescript]class - protected

private 은 다접근 안됨.

 

protected는 부모자식에서만 됨.

 

 

class Parent{

    private privateProp:string;

    protected protectedProp:string;

 

    constructor(){

    }

}

 

class Child extends Parent{

    constructor(){

        super();

 

        this.protectedProp='protected';

    }

}

 

console.log(new Child());

 

==========================================================

 

class Person{

    protected _name:string = 'kim';

    private _age:number=null;

}

 

class Child extends Person{

    setName(){

        this._name='fuck';

    }

}

 

const person:Child = new Child();

 

person.setName();

console.log(person);

  Comments,     Trackbacks