虽然 C# 的 List<> 与下面的不同,但类似这样
function Player(playerName, gameCenterPlayer)
{
this.playerName = playerName;
this.GameCenterPlayer = gameCenterPlayer; // i'm going to assume this has been calculated elsewhere, and all we need now is a boolean.
}
function playerDataLoaded(players) {
this.players = players
this.getCenterPlayer = function() {
var i = 0
while (i < players.length) {
if (players[i].GameCenterPlayer) {
console.log(players[i].playerName + " is the center player!");
}
i++;
}
}
}
var player1 = new Player("Ted", 0);
var player2 = new Player("Jane", 1);
var player3 = new Player("Doug", 0);
Players = new playerDataLoaded([player1, player2, player3]);
Players.getCenterPlayer()