I am aware of it being frowned upon to do something like write C# in JavaScript. (See Write Cobol in any language if you don't know what I'm talking about.)
But as a judgement call I think we could stand to have a relatively simple check for values that are null
or empty. So I'm Looking for feedback on this implementation of String.isNullOrEmpty
.
String.isNullOrEmpty = function (value) {
try {
value = value.toString();
} catch (e) {
return true;
}
return (!value || value == undefined || value == "" || value.length == 0);
}
Revision 1:
String.isNullOrEmpty = function (value) {
return (!value || value == undefined || value == "" || value.length == 0);
}
toString
onvalue
? – user786653 Oct 25 '11 at 19:50return !value;
suffice? – James Khoury Oct 26 '11 at 1:16