最近我从我们的平台收到一些错误消息,消息类似于 undefined is not an object (evaluating 't.id')
,但关联的代码是 bar(xxx. id)
IMO,即使它会抛出错误,它应该是can't read property id of undefined
而不是undefine is not an object (evaluating 't.id')
那么,谁能告诉我为什么会发生这种情况?谢谢!
最佳答案
好吧,我想可能是因为不同的浏览器有不同的错误处理
在 Safari 中:
在 Chrome 中:
但我认为错误消息应该是相同的,因为 ECMAScript 规范对此有明确的定义
这是不正确的,来自 @Bergi 的评论:
But I think the error message should be same because the ECMAScript spec has clear definition about this" - not at all. It just says that a TypeError should be thrown, and the implementation may decide to provide an appropriate (helpful) error message as they see fit. It doesn't even have to be in English
关于javascript - 'can' t read property foo of undefined' 和 'undefined is not an object' 之间有什么区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48179713/