arguments.callee: A dren.ch Endorsement
I mostly agree with Mr. JSON's ECMAScript recommendations but not this:
The following features should be depreciated.
[...]
arguments.callee.
It might have a goofy name but arguments.callee is way too useful (inside a Javascript function, this is a reference to the function itself). I don't mean anonymous recursive functions, though that's still kind of cool. Say you wanted a "sequence" function. With arguments.callee:
function sequence () {
var me = arguments.callee;
if (! me.n) me.n = 0;
return me.n++;
}
Without:
var sequence = (function () {
var n = 0;
return function () { return n++ };
})();
You can argue that the "without" version is better but I'm not going to agree with you.
9/12/2006 update: This works and is probably clearer than either of the above:
var sequence = function () { return sequence.n++ };
sequence.n = 0;
It manages to avoid arguments.callee and function-within-a-function closure. It also fixes the (for me) biggest problem with the arguments.callee version: the test for undefined n on every call. But there are a couple minor downsides: the function needs to know its name, and it's not self-contained. Maybe you don't care.
8/15/2007 update: A Canadian named Peter discusses similar problems though he's into using the term "pattern".