JavaScriptコンストラクタ内に、ブレークポイントを使用してステップインしたときに正しい値に設定される変数があります。しかし、ブレークポイントなしで実行すると、変数(私が与えた配列であるはずです)はコンソールに空の配列として現れます。私は、hereと記載されているように、プロトタイプのget/setプロパティを使用するかどうかはわかりません。また、私はWebkitで作業しています。なぜ誰かが私にその理由を説明するのを手伝ってもらえれば、私はそれを感謝します。ありがとう!だから、コンソールを使用してステップ実行したときに正しい値を与えるJavaScript変数
function Box(inElement){
var self = this;
this.element = inElement;
this.boxes = (function() {
var boxes = [];
for (var i = 0; i < inElement.childNodes.length; ++i) {
if (3 !== inElement.childNodes[i].nodeType) {
boxes.push(inElement.childNodes[i]);
}
}
return boxes;
})();
this.rotation = [-40,-20,0,20,40];
}
Box.prototype =
{
get rotation(){
return this._rotation;
},
set rotation(rotArray){
console.log('rotArray');
console.log(rotArray);
var thisrot;
this._rotation = rotArray;
for(var i=0; i<this.boxes.length; i++){
thisrot = rotArray.shift();
this.boxes[i].style.webkitTransform = 'rotateY(' + thisrot + 'deg) translateZ(170px)';
}
}
}
function loaded()
{
new Box(document.getElementById('area'));
}
window.addEventListener('load',loaded, true);
、いくつかのあいた後、私はそのboxes.pushを発見(inElement.childnodes [i]は、問題の行である。コメントアウトすると予想されるように、値が出てくる。
匂い競争状態のように。電子コード? – FishBasketGordo
必須ショー。コード。 –
これは範囲の問題かもしれません - あなたのコードを投稿してください。 – yoozer8