FACEBOOK”;未捕获的类型错误:无法读取属性'type'“未定义”;

FACEBOOK "Uncaught TypeError: Cannot read property 'type' of undefined "

本文关键字:未定义 属性 读取 type 类型 FACEBOOK 错误      更新时间:2023-09-26

在我的移动应用程序上,我不时会收到这个错误和这个错误

未捕获的类型错误:无法读取未定义的属性"type"

此错误来自以下行;

if ((post.attachment.media !== undefined) && (post.attachment.media[0].type == "photo"))

我只是偶尔会收到,我想这取决于新闻推送。有时它工作得很完美,不会出错。有什么想法吗?

错误表明,即使定义了post.attachment.media,它也不是数组或是空数组。你可以用来保护它

if ((post.attachment.media !== undefined) && 
    (post.attachment.media.length > 0) &&
    (post.attachment.media[0].type == "photo"))