LoginSignup
2
2

More than 5 years have passed since last update.

TypeScriptでの基本的なクラスの書き方

Posted at

TypeScriptでは、クラスを以下のように書くことができます。

class.ts
class HogeClass {
    foo: string;
    constructor(foo: string) {
        this.foo = foo;
    }
}

コンストラクタに対して「constructor」と明記するのが、他のメジャーなOOP言語と異なる部分ですね。

JavaScriptの場合ですと、オブジェクトに属した変数のことを「プロパティ」と読んでいましたが、TypeScriptの仕様書によりますと、上記のfooのような、クラスに属した変数を「Members」と呼んでいます。なので、C++のように「メンバ変数」と呼んでもいいのかもしれません。

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2