我使用這個代碼來測試對象是否爲空或空:我的'isNullOrEmpty'函數是否很好?
var isNullOrEmpty = function(obj) {
// this should handle if someone defines a variable named 'undefined'.
if(obj == null || typeof(obj) == 'undefined' || obj == "") {
return true;
}
return false;
}
有什麼我失蹤?
謝謝。
對於這樣的嚴格比較,您應該使用[identity operator](http://stackoverflow.com/a/359509/596068),即正確使用'==='與'=='。 – Alex 2012-07-25 13:57:09
是不是'if(obj)'或多或少等於你想要在這裏做什麼? – 2012-07-25 13:57:58
你必須告訴我們變量是「空的」意味着什麼。 – 2012-07-25 14:00:34