Catchall invocation for 'null' and 'undefined' (or: how to be a disruptive influence in 3 easy steps)
bedney at technicalpursuit.com
Fri May 15 10:45:25 PDT 2009
I sent this about 1.5 weeks ago, but have gotten no responses. I can
attribute this to 2 possible items:
1. I made the mistake of replying to an existing message so this one
got buried under a thread it shouldn't have.
2. Folks were so horrified as to what I was asking for that they
really just wished I would go away :-).
I'll repeat the message here. If the answer is #2, please let me know
and I'll crawl back under my rock :-).
Well, Sister Eugenia always did say I was a disruptive influence in
grade school - guess I haven't changed much :-).
Let me throw another idea into the mix and churn the pot a bit more.
Many moons ago when I was a Smalltalker, I always liked the fact that
'nil' in Smalltalk was a singleton instance of UndefinedObject... and
you could add methods to UndefinedObject :-).
When I switched to JS, I found out that 'null' and 'undefined' were
'special' and weren't instances of anything I could add methods to
(cue wailing and gnashing of teeth).
I always thought it would be most interesting if the following were
true: 'null' was the singleton instance of the Null type and
'undefined' was the singleton instance of the Undefined type.
Then, I could do the following (which would have saved me a lot of
debugging time over the years):
(Using the older __noSuchMethod__ syntax):
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');
My business partner Scott has bugged Brendan about this in the past
and he mentioned that ES3 was too set in its ways to do anything like
this, but I figured maybe with Harmony on the horizon, the issue could
be revisited :-). I have no idea regarding the implications of such a
change and therefore leave it to you all to consider those implications.
More information about the es-discuss