別プラグインの関数からオブジェクトを生成する方法が知りたいです。
通常以下のようにすればnew演算子でWindow_Hogeを生成できるかと思います。
コード: 全て選択
(function() {
function Window_Hoge() {
this.initialize.apply(this, arguments);
}
Window_Hoge.prototype = Object.create(Window_Base.prototype);
Window_Hoge.prototype.constructor = Window_Hoge;
Window_Hoge.prototype.initialize = function(x, y, w, h) {
Window_Base.prototype.initialize.call(this, x, y, w, h);
};
Scene_Hoge.prototype.createHogeWindow = function() {
this._hogeWindow = new Window_Hoge(x, y, w, h);
this.addWindow(this._hogeWindow);
};
})();
しかし以下のようにこれを分けて別プラグインとした場合Window_Hoge関数を参照して
生成できません。ブロックが分かれてしまうということはわかります。
コード: 全て選択
(function() {
function Window_Hoge() {
this.initialize.apply(this, arguments);
}
Window_Hoge.prototype = Object.create(Window_Base.prototype);
Window_Hoge.prototype.constructor = Window_Hoge;
Window_Hoge.prototype.initialize = function(x, y, w, h) {
Window_Base.prototype.initialize.call(this, x, y, w, h);
};
})();
コード: 全て選択
(function() {
Scene_Hoge.prototype.createHogeWindow = function() {
this._hogeWindow = new Window_Hoge(x, y, w, h);
this.addWindow(this._hogeWindow);
};
})();
これの解決策として以下のようにfunction Window_Hoge()を(function() { })();の外に出せば
(つまりはグローバル化?)他のプラグインから参照して生成できますが
function Window_Hoge()関数を外に出さずに別プラグインからこの関数を生成することは可能なのでしょうか?
コード: 全て選択
function Window_Hoge() {
this.initialize.apply(this, arguments);
}
(function() {
Window_Hoge.prototype = Object.create(Window_Base.prototype);
Window_Hoge.prototype.constructor = Window_Hoge;
Window_Hoge.prototype.initialize = function(x, y, w, h) {
Window_Base.prototype.initialize.call(this, x, y, w, h);
};
})();