为什么全局 var debug 被评估为 [object Object] 而不是 1?考虑这段代码:
var debug = 1;
function hum(mess) {
alert('hum alert debug == ' + debug);
console.log('hum console.log debug == ' + debug);
if (debug == 1) {
console.error('hum mess == ' + mess);
} else {
console.error('hum debug != 1 mess == ' + mess);
}
}
当我的代码第一次运行时,eval 是正确的,所以我的警报显示“debug==1”,但稍后(可能在 phonegap 完成加载之后)它开始给我 debug==[object Object]。我正在使用 xcode 和 iphone 模拟器使用 phonegap for ios 进行开发。
谢谢
最佳答案
看起来您已将 debug
声明为全局变量,它可能会被稍后加载/执行的其他代码重新分配。尝试更改变量名称或使其不是全局的。
关于javascript - 为什么全局 var 调试被评估为 [object Object],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6779069/