【发布时间】:2016-08-14 00:27:22
【问题描述】:
function player(name, goals, games) {
this.name = name;
this.goals = goals;
this.games = games;
}
var ricky = new player('Ricky', 7, 15);
var tom = new player('Tom', 15, 17);
var phil = new player('Phillip', 9, 14);
var jerry = new player('Jerry', 11, 15);
var randy = new player('Randy', 4, 16);
var sam = new player('Sam', 5, 11);
function locTeams(name, town, wins, playerOne, playerTwo, playerThree) {
this.name = name;
this.town = town;
this.wins = wins;
this.playerOne = playerOne;
this.playerTwo = playerTwo;
this.playerThree = playerThree;
}
var tigers = new locTeams('Great Tigers', 'Clayton', 9, ricky, tom);
var pantheon = new locTeams('The Pantheons', 'Brookedale', 8, jerry, randy);
teams = [tigers, pantheon];
var totalGoalsState =
我需要一种简单的方法让totalGoalsState 等于teams 数组中玩家的累计玩家目标。另外,我如何将playerThree 与其他新玩家之一(例如phil 或sam)填充到像老虎队或万神殿这样的球队之一。
【问题讨论】:
-
locTeams的构造函数需要 5 个参数,你传递了 4 个。你也错过了this.playerThree = playerThree。 -
@AleksandarĐokić - 它并不真正需要 5 个参数,它可以有 5 个参数。
-
@adeneo 是的,但他没有在方法中的任何地方设置
playerThree......他应该,因为它在构造函数中。 -
糟糕,忘了补充,我修好了。
标签: javascript arrays variables object new-operator