错误如下:
问题分析:
错误类型
TypeError.
什么地方出错了?
出现了与期望不符的类型。 这个错误常常由 undefined 或 null 值引起。
此外,某些方法,例如 Object.create() 或 Symbol.keyFor(), 要求必须提供特定类型的参数。
解决方法:
要解决空指针以及 undefined 或 null 值的问题, 你可以使用 typeof 操作符, 例如:
if (typeof foo !== 'undefined') {
// Now we know that foo is defined, we are good to go.
}
示例1:
if (typeof readoutToast == 'undefined') {
readoutToast.innerText = '(' + loc.x.toFixed(0) + ', ' + loc.y.toFixed(0) + ')';
}
示例2:
if (typeof readoutToast == 'undefined') {
readoutToast.style.display = 'block';
}