Node.js forEach:无法读取未定义的属性"[对象数组]" [英] Node.js forEach: cannot read property '[object Array]' of undefined
问题描述
我以前从未见过.我已对其进行更新以解决此问题,同时在Node.js 6.3.0和6.9.1 LTS上都发生了此错误.
I've never seen this one before. This error occurred on both Node.js 6.3.0 and 6.9.1 LTS, which I updated to in an effort to resolve this.
我正在尝试根据我拥有的一些数据来构建游戏的统计数据,这并不是特别重要.重要的是我的Game类中的以下功能失败了:
I'm trying to build stats for a game based on some data I have, not particularly important. What is important is that the following function, part of my Game class, fails:
computeStats() {
var stats
, roster
, team, opp, scoreState, oppScoreState
, TOI = this.calculateTOIData()
, eventCounter = this.calculateEventData()
[['home', 'away'], ['away', 'home']].forEach((teams) => { //this is line 74 / error source
team = teams[0];
opp = teams[1];
roster = this[team].roster;
stats = {
//some assignments occur here from my TOI and eventCounter objects
}
this.setStats(team, stats);
})
}
抛出的错误是
TypeError: Cannot read property '[object Array]' of undefined
at GameTracker.computeStats (/Users/nawgszy/repo/lib/Game.js:74:5)
at new GameTracker (/Users/nawgszy/repo/lib/Game.js:39:10)
我不知道这怎么可能.阵列是硬编码的,就在那.有任何想法吗?我可以解决它,但是我发现这种特定的结构是生成想要使用的统计信息的最简单方法.
I have no idea how this is possible. The array is hard-coded, right there. Any ideas? I can work around it, but I find this specific structure to be the easiest way to generate stats like I want to use.
推荐答案
我猜这是ASI惹的祸.在eventCounter = this.calculateEventData()
之后添加分号,并查看其运行方式.
It's the ASI that is messing with you I guess. Add a semicolon after eventCounter = this.calculateEventData()
and see how it runs.
更多信息: http://benalman.com/news/2013/01/advice-javascript-semicolon-haters/
这篇关于Node.js forEach:无法读取未定义的属性"[对象数组]"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!