クラスの書き方
記述方法
test.ga
(function (global) {
/**
* コンストラクタ
* @constructor
*/
var Test = function () {
};
/**
* メッソド
* @returns {boolean}
*/
Test.prototype.main = function () {
return true;
};
global.Test = Test;
})(this);
サンプル
test.ga
function _runTest() {
// Testクラスのインスタンス化
var test = new Test();
// Testクラスのmainメソッドを実行
test.main();
// Testクラス内のメンバ変数に設定する
test.setAaa('あああ');
// Testクラスン内のメンバー変数を出力する
test.output();
}
(function (global) {
/**
* @constructor
*/
var Test = function () {
/**
* コンストラクタ
*
* 「var test = new Test();」のタイミングで実行(インスタンス生成時に実行)
*/
};
/**
* @returns {boolean}
*/
Test.prototype.main = function () {
/**
* メソッド
*
* 「test.main();」のタイミングで実行
*/
Logger.log('mainが実行されました');
return true;
};
/**
* @returns {boolean}
*/
Test.prototype.setAaa = function (value) {
Logger.log('setAAAが実行されました');
/**
* メンバー変数設定
* 引数「value」をメンバー変数に設定する
*/
this.aaa = value;
return true;
};
/**
* @returns {boolean}
*/
Test.prototype.output = function () {
Logger.log('outputが実行されました');
/**
* メンバー変数をログに出力する
*/
Logger.log(this.aaa);
return true;
};
global.Test = Test;
})(this);