有什么区别
TypeError: ... is undefined
和
ReferenceError: ... is not defined
?
最佳答案
ReferenceError
当您尝试使用根本不存在的变量时发生。
TypeError
发生在变量存在时,但您尝试执行的操作不适合它包含的值的类型。在详细消息显示“未定义”的情况下,如果您有一个值为特殊 undefined
值的变量,并且您尝试访问它的属性,则可能会发生这种情况。
参见 http://javascriptweblog.wordpress.com/2010/08/16/understanding-undefined-and-preventing-referenceerrors/进行一些与此相关的讨论。
关于javascript - TypeError 和 ReferenceError 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12589391/