我的观念是否正确?

我尝试在Node.js中编写高级应用程序,但是我不确定我的代码思路是否正确。 首先我想谈谈我的申请。 我的应用程序将显示在线结果没有刷新页面。 首先,我必须创build一个阵容,队伍将会玩。 假设我们有这样的2场比赛:

var Schedule = [ {id:199, team1:{name:"Detroit",id:24319}, team2: {name: "San Antonio", id:32543}, date: "20.11.2015 12:00"}, {id: 200, team1: {name: "Boston", id: 23113}, team2: {name: "Los Angeles", id:25966}, date: "19.12.2015 10:00"} ]; 

其次,当比赛要开始的时候,我必须开始配合创造一个对象。 我把这个匹配的属性放入数组中:“匹配”。

 var Matches = []; Schedule.forEach(function(a,b){ Schedule.splice(a,1); new Match(a.team1,a.team2,a.id); var matchProperties = {"id": a.id, "team1": a.team1 , "team2":a.team2, "date": a.date, "result1":0, "result2":0, "minute":0 }; Matches.push(matchProperties); 

我匹配的工厂是这样的:

 function Match(team1,team2,id) { this.team1.name = team1; this.team2.name = team2; this.id = id; this.initialize(); }; Match.prototype = { id: 0, minute: 0, team1: {"name": ""}, team2: {"name": ""}, result1: 0, result2: 0, events: [], initialize: function() { var that = this; setInterval(function(){ that.minute++; Matches.forEach(function(a,b,theArray) { if(a.id == that.id) { theArray[b].minute = that.minute; if(that.minute == 5) that.score(theArray[b].team1,3); if(that.minute == 10) that.score(theArray[b].team1,2); if(that.minute == 20) that.score(theArray[b].team1,3); if(that.minute > 90) return; } }); },1000); }, score: function(team,points) { var that = this; Matches.forEach(function(a,b,theArray) { if(a.id == that.id) { if(team.name == theArray[b].team1){ theArray[b].result1 = theArray[b].result1 + points; } if(team.name == theArray[b].team2) theArray[b].result2 = theArray[b].result2 + points; var message = that.getAction('score',team,points); that.events.push(message); } }); } } 

现在,我将数据发送到结果页面:

 setInterval(function() { io.sockets.emit('results', Matches); },1000); 

现在,我的代码有一个问题,因为每个方法都需要每个函数,并且我认为这是获取匹配数然后在这个匹配中进行修改的错误方法。 每次执行此命令:new Match(a.team1,a.team2,a.id); 应该是单独的对象,例如方法评分应该只改变一个Match作为参考。

我有问题,这是正确的方式? 也许你有什么想法来改善我的代码? 每个答复将不胜感激。