问题描述
var count_particles,stats,update;
stats = new Stats();
stats.setMode(0);
stats.domElement.style.position = "absolute";
stats.domElement.style.left = "0px";
stats.domElement.style.top = "0px";
document.body.appendChild(stats.domElement);
count_particles = document.querySelector(".js-count-particles");
update = function () {
stats.begin();
stats.end();
if (window.pJSDom[0].pJS.particles && window.pJSDom[0].pJS.particles.array) {
count_particles.innerText = window.pJSDom[0].pJS.particles.array.length;
}
requestAnimationFrame(update);
};
requestAnimationFrame(update);
它说 未捕获的 ReferenceError:未定义统计数据 请问有人可以帮忙吗?
解决方法
错误不是标题中的 stats is not defined
- 它是 Stats is not defined
。请注意大写字母 - 您缺少 Stats
类的定义。
根据您的代码,stats
已定义,但 Stats
未定义。你的标题有错别字。
Stats 应该是一个从未定义的类。这是你如何在 Javascript 中创建一个类:
class ClassName { constructor() { ... } }
在您的情况下,类名是 Stats,构造函数是类中的方法,例如代码中的 setMode()
。
有关详细信息,请访问 Javascript Classes at Mozilla