我不能让它工作:
var global_variables = {
players: []
};
var player = function(properties){
this.width = properties.width;
this.height = properties.height;
this.position = properties.position;
this.position.x = properties.position.x;
this.position.y = properties.position.y;
}
function load_players(){
global_variables.players.push(
[
new player(
{
width: 10,
height: 10,
position: {
x: 50,
y: 50
},
colour: '#ff0000'
}
)
]
);
}
function init(){
var ctx = load_canvas();
load_players();
for(a in global_variables.players){
var _this = global_variables.players[a];
alert(_this.colour);
}
}
alert(_this.colour) 只是提醒未定义。有任何想法吗?