How to check a null value with an extension method using Object.prototype
<p>There are a variety of places where I need to check if a JavaScript variable is null or empty string so I wrote an extension method that looks like this:</p>

<pre><code>Object.prototype.IsNullOrEmptyString = function()
{
    return (this == null || (typeof this === "string" &amp;&amp; this.length == 0));
}
</code></pre>

<p>I then call it like so:</p>

<pre><code>var someVariable = null;

if (someVariable.IsNullOrEmptyString())
    alert("do something");
</code></pre>

<p>But that doesn't work because, at the point of evaluation in the if statement, someVariable is null.  The error I keep getting is "someVariable is null".</p>

<p>You can see it live here: <a href="http://jsfiddle.net/AhnkF/" rel="nofollow">http://jsfiddle.net/AhnkF/</a>  (run in Firefox and notice the error console)</p>

<p>Is there anyway to do what I want and have a single extension method check for null and other things at the same time?</p>
