2016-09-06 4 views
1

나는 배우에 관한 정보를 담고있는 배우 클래스뿐만 아니라 영화 캐릭터에 관한 json 데이터를 나타내는 Moviecharacter 클래스를 가지고있다. 내가 중복 속성을 사용하지 않고 내 Moviecharacter 클래스로 액터 클래스를 추가 할 :Typescript : 클래스 내의 클래스

// actor class stores general information about an actor in a json file 
export class Actor{ 
    name: string; 
    id: number; 
} 

// duplicated attributes name and id: 
export class MovieCharacter { 
    name: string; 
    id: number; 
    character: string; 
} 

하지만 난 이런 걸 원하는 : 영화 배우와 MovieCharacter에 대한

내 버전이 있습니다

// without duplicated Attributes: 
export class MovieCharacter { 
    Actor(); // not working 
    character: string; 
} 

을 어떤 도움을 주시면 감사하겠습니다.

답변

2

// 중복 속성이없는 :

당신이 상속 찾고있는 용의자 :

// actor class stores general information about an actor in a json file 
export class Actor { 
    name: string; 
    id: number; 
} 

// Inherits name and id from Actor 
export class MovieCharacter extends Actor { 
    character: string; 
} 

어떤 도움이 문서는 : https://basarat.gitbooks.io/typescript/content/docs/classes.html

+0

큰, 상속 내가 찾고 있었던 일이었다 :) – SirCheckmatesalot

1

당신은 첫째로 멤버 지정해야합니다 : 당신은 당신이 다음을 수행 할 수 있습니다 건설 클래스의 새 인스턴스를 만들 싶었다면 ... "이름 입력"

class MovieCharacter { 
    actor: Actor; 

    constructor() { 
     this.actor = new Actor(); 
    } 
}