当我致电renderFrame
时,尝试访问newLine[i]
会引发错误
Uncaught TypeError: Cannot read property '0' of undefined
这是为什么?我已经包含了相关的代码。
rows : ["-","-","-","-","-","-","-","-","-","-",],
generateLine : function(){
var result = new Array(10);
for(var i = 0; i < result.length; i++){
result[i] = " ";
}
},
renderFrame : function(){
var newLine = this.generateLine();
for(var i = 0; i < this.rows.length; i++){
console.log(newLine[i]);
}
},
答案 0 :(得分:17)
你忘记了
return result;
在generateLine()
所以newLine
现在未定义。因此Cannot read property '0' of undefined