私は、確認ウィンドウまたはダイアログフォームを表示できる関数を作成しようとしています。これらの2つの関数は同じウィンドウ内にあるので、両方でコードを再利用するかもしれません。JavaScriptで複数の関数を持つクラス
私はそれは問題は、私はどこのウィンドウを描画するかわからないということです
const MyWindow = function (options) {
};
MyWindow.prompt = function (options) {
..
};
MyWindow.confirm = function (options) {
...
}
MyWindow.alert = function (options) {
...
}
のようなものでなければなりませんね。私は新しい方法
const MyWindow = function (options) {
};
MyWindow.createElements = function (options) {
this.window = document.createElement('div');
this.window.style.height = 300;
this.window.style.width = 300;
document.body.insertBefore(this.window, document.body.childNodes[0]);
};
MyWindow.prompt = function (options) {
this.createElements();
this.window.style.background-color = 'red';
};
が、this.createElements()
とthis.window
を作成しようとした
はprompt()
機能からアクセスすることはできません。
どのように通常このようなものを開発していますか? ES6クラスを使うべきですか?
これはオブジェクトのように 'MyWindow'関数を使用しています(これは可能ですが)。それを関数の代わりにオブジェクトにする。 – Teemu
'MyWindow'はインスタンスのシングルトンモジュールまたはコンストラクタであるはずですか? – Bergi
はい、ES6クラスを使用する必要があります。 – Bergi