1
JavaScript構造函數中有一個變量,在逐步使用斷點時似乎設置爲正確的值。但是,當運行沒有斷點時,變量(應該是我給它的數組),在控制檯中顯示爲空數組。我不知道是否使用原型的get/set屬性,如here所述。另外 - 我在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]是有問題的線路。當註釋掉,價值出來符合市場預期。
氣味像競賽條件,你可以張貼索姆e代碼? – FishBasketGordo
必須。顯示。碼。 –
這可能是一個範圍問題 - 你可以發佈你的代碼嗎? – yoozer8