Extending Date prototype - can this ever be null?
<p>I'm trying to extend the Date prototype in JavaScript like this:</p>

<pre><code>Date.prototype.toLastDayOfPreviousMonth = function() {
    return new Date(this.getFullYear(), this.getMonth(), 0);
}
</code></pre>

<p>However I'm not sure if I can ever expect <code>this</code> to be null here. My thinking is that if someone ever wants to do something like this:</p>

<pre><code>var dateA = null;
dateA.toLastDayOfPreviousMonth();
</code></pre>

<p>The above function won't ever get called - because we're calling this on null and not Date. I'm not interested in quirks like calling the function through apply etc. Just 'genuine' usage <code>date.toLastDayOfPreviousmonth();</code></p>

<p>One of the similar extensions I found had this check:</p>

<p><code>var obj = this instanceof Date ? this : null;</code> Does it have any sense at all?</p>