我不明白为什么我不能创建一个新对象
错误:Uncaught TypeError: Cannot set property '0' of undefined
我在线路代码上遇到错误。 this.gameAnimals[i] = {};
this = Game;
gameAnimals[0] = 'frog';
那为什么我有错误?非常感谢。
var Game = {
init: function(){
this.property1 = 1;
this.property2 = 2;
this.property3 = 3;
this.property1000 = 1000;
},
cons: function(gameAnimals){
for(var i = 0; i < gameAnimals.length; i++){
this.gameAnimals[i] = {};
}
},
};
var gameAnimals = ['frog', 'lion', 'cat'];
Game.cons(gameAnimals);