if(typeof window !== undefined) {
console.log("this should print only if window object actually exists")
}
在检查窗口是否未定义时,有人可以告诉我为什么NodeJS(0.6.5)无法正常工作吗?如果你调用typeof window,你会得到未定义但仍然无法正常工作。有什么想法吗?
答案 0 :(得分:7)
if(typeof window !== 'undefined') {
console.log("this should print only if window object actually exists")
}
typeof返回一个字符串