繁体   English   中英

TypeError:无法读取未定义的属性“0”

[英]TypeError: Cannot read property '0' of undefined

当我调用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]);
    }
},

你忘了

return result;

generateLine()的末尾

所以newLine现在未定义。 因此Cannot read property '0' of undefined

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM