我不能得到這個工作:推新功能到一個數組 - 的Javascript
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);
}
}
警報(_this.colour)只是提醒不確定。有任何想法嗎?
'load_players'不叫? –
我更新了代碼以表示我將它稱爲的位置......並且再次。嘿嘿 – Jimmyt1988