私はボタンプログラムに取り組んでいます。Button
HTML で見つかった各ボタンに割り当てられたオブジェクトがあります。ボタンにはさまざまな種類があるため、それぞれの種類に適したオブジェクトを作成する別のコンストラクターが必要です。
Button
これらの個別のコンストラクターを呼び出す方法は理解していますが、オブジェクトに特定の変数を適用するためにコンストラクターに何を入れればよいかわかりません。
ボタン オブジェクトの例:
var Button = function(){
if (buttonType == 'type1'){
buttonType1(); //set onclick, onmouseover/mouseout, onmousedown/mouseup
}
else{
buttonType2(); //set different ways to handle events
}
}
Button
オブジェクトの作成方法:
var buttons = document.getElementsByClassName('button');
Buttons = new Buttons_Objs(); //An object to store references to all Button Objs.
for (i = 0 ; i < buttons.length ; i++){
button = buttons[i];
buttonType = button.getAttribute('type');
Buttons['button' + i] = new Button(button, buttonType);
}
Button
onclick などを設定するためにこれらの関数をどのように構成すればよいでしょうか。また、オブジェクトを混雑させたくない場合は、それらを格納するのに適した場所はどこでしょうか。