[TypeScript]クラス
class Parent{ static PI:number = 3.1415926535; protected static readonly gratio = 1.618; public name:string; public prop:number = 10; protected gender:string; private _abc:number; constructor(name:string){ this.name = name; } get abc():number{ return this._abc; } set abc(value:number){ this._abc = value; } showMessage(message:string){ console.log(`Hello ${this.name}!. ${message}`); } } class Child extends Parent{ public prop:number = 22;//プロパティのオーバーライド public age :number; private prop2:string; constructor(name:string,age:number){//constructorのオーバーライド super(name); this.age = age; } showMessage(message:string){//メソッドのオーバーライド console.log(`Hello ${this.name}!. ${message} age:${this.age}`); } }
通常
class Article{ public name:string; protected prop:number = 10; private prop2:number = 10; constructor(name:string,prop:number,prop2:number){ this.name = name; this.prop = prop; this.prop2 = prop2; } }
省略記法
class Article{ constructor( public name:string, protected prop:number, private prop2:number ){} }