2012-02-24 35 views
2
if(typeof window !== undefined) { 
    console.log("this should print only if window object actually exists") 
} 

有人可以告訴我爲什麼NodeJS(0.6.5)在檢查窗口沒有被定義時是否工作不正確?如果你調用typeof窗口,你會得到未定義的,但仍然無法正常工作。有任何想法嗎?窗口對象不存在但仍然存在於NodeJS中

+0

解決......沒有意識到,實際上你把「不確定」,而不僅僅是普通的舊的定義。 – jimmy 2012-02-24 17:29:06

回答

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

的typeof返回一個字符串

相關問題