注意!!!
判斷一個變量chat_websocket是否存在:
if( "undefined" == typeof(chat_websocket) || null == chat_websocket ){}
把值放在前面,變量放在后面
而不是像下面這樣寫:
if( typeof(chat_websocket) == "undefined" || chat_websocket == null ){}
雖然等價,但是呢像上面的寫法被認為是技術大牛、有經驗的人,因為上面的寫法可以避免你一不小心將代碼寫成這樣:if( typeof(chat_websocket) = "undefined" || chat_websocket = null ){},的時候出現報錯。寫成這樣:if( "undefined" = typeof(chat_websocket) || null = chat_websocket ){}是不會報錯的。