LoginSignup
2
2

More than 5 years have passed since last update.

【JScript】クラスを定義する

Last updated at Posted at 2014-05-03

クラス定義

JScriptには class のような予約語が無いですが、functionを使ってクラスを定義することが出来ます。

ファイル名は任意。

// TestClassクラスのコンストラクタとする
function TestClass(intParam)
{
    // プロパティ
    this.value = intParam;

    // メンバ関数
    this.Output = TestClass_Output;     // 関数名は何でもいい
}

// valueを出力する関数
function TestClass_Output()
{
    WScript.Echo("Value is " + this.value);     // プロパティは this を付ける
}


// インスタンス生成してメンバ関数呼び出し
var obj = new TestClass(10);
obj.Output();
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