Node.js 窗口对象不存在,但仍存在于NodeJS中

Node.js 窗口对象不存在,但仍存在于NodeJS中,node.js,Node.js,有人能告诉我为什么在检查窗口是否未定义时NodeJS(0.6.5)不能正常工作吗?若你们调用typeof窗口,你们会得到未定义的,但上面的条件仍然不能工作。有什么想法吗 if(typeof window !== undefined) { console.log("this should print only if window object actually exists") } typeof返回一个字符串已解决。。。我不知道你实际上必须把“undefined”改为普通的undefined

有人能告诉我为什么在检查窗口是否未定义时NodeJS(0.6.5)不能正常工作吗?若你们调用typeof窗口,你们会得到未定义的,但上面的条件仍然不能工作。有什么想法吗

if(typeof window !== undefined) {
  console.log("this should print only if window object actually exists")
}

typeof返回一个字符串

已解决。。。我不知道你实际上必须把“undefined”改为普通的undefined。有趣的是它返回undefined而不是引用错误,知道为什么吗?
if(typeof window !== 'undefined') {
  console.log("this should print only if window object actually exists")
}