Catchall invocation for 'null' and 'undefined' (or: how to be a disruptive influence in 3 easy steps)

Mike Shaver mike.shaver at gmail.com
Fri May 15 11:33:43 PDT 2009


On Fri, May 15, 2009 at 10:45 AM, William Edney
<bedney at technicalpursuit.com> wrote:
> Then, I could do the following (which would have saved me a lot of debugging
> time over the years):
>
> Null.prototype.__noSuchMethod__ = function (id, args)
> {
> alert('you were a bad boy and tried to send ' + id + ' to null');
> }
>
> Undefined.prototype.__noSuchMethod__ = function (id, args)
> {
> alert('you were a bad boy and tried to send ' + id + ' to undefined');
> }

This seems like something that can be addressed by "quality of
implementation" today, at least as far as error messages go.  I think
it's entirely possible for the error paths to give more context, so
I'm wondering if there are other significant use cases for creating
Null and Undefined.

(And would you then want toString and valueOf hooks to be honoured?
Would Undefined and Null be truthy or falsy?  Boolean is enough of a
mess on that score...)

Mike


More information about the es-discuss mailing list