我想知道为什么我pageCounter
的页面对象(见下文)被视为字符串而不是 int?为什么javascript不解释变量,而是使用变量名作为文字字符串?
for (var i in stories){
//reset the counter when it hits the number of stories per page
if (counter >= divsByPage) {
counter = 1;
pageCounter++;
}
//turn all the stories off
//stories[i].style.display = "none";
//insert a new story under a page array
pages.push({pageCounter:stories[i]});
counter++;
}
console.log(pages[1]);
输出Object { pageCounter=[1]}
。