0

ノードごとに関数を呼び出そうとしています。notchlick 関数でノッチ配列が定義されている場合、配列は作成されません。関数の外に配置すると、配列には元のノードのみが含まれ、クローンは含まれません。配列はhtmlcollectionなので、ライブリストになると思います。

let notch;

poppin = function () {

ole.classList.replace ('okay', 'olay');

ulay.classList.replace ('unlay', 'ulay');

bup[0].classList.replace ('bup', 'cup');

pegs.classList.replace ('pegs', 'legs');

if (!ran) {

    notches();
    switches();
}

count = 0;
}

let notches = function () {

for (a = 0; a < tn; a++) {

    let svgc = svg.cloneNode(true);

    pegs.append(svgc);
}   

ran = true;

}

notch = Array.prototype.slice.call(document.getElementsByTagName('svg'));

notchlick = function (k) {

notch[k].onclick = function () {

    spright();
    spleft();   
    bup[count].classList.replace ('cup' , 'bup');

    count = k;
    bup[count].classList.replace ('bup' , 'cup')        
}
}

switches = function () {

for (k = 0; k < notch.length; k++) {

    notchlick(k);
}
}

複製されたノードは、オリジナルのようには動作しません。示されているように、配列が関数の外で宣言されている場合、これが問題の原因ですか? また、クロージャーについての私の理解を考えると、関数にネストされたときに配列が登録されない理由がわかりません。

4

0 に答える 0