Ye olde arguments argument (was: Topic list - pending changes and issues for the ES3.1 spec)

liorean liorean at gmail.com
Thu Sep 11 16:07:36 PDT 2008


2008/9/12 Jon Zeppieri <jaz at bu.edu>:
> But that's a somewhat flippant response.  More to the point: if you
> want recursion, one way or another, you need to be able to refer to
> the function in question.  'arguments.callee' allows you to refer to
> it but violates the Tennent Correspondence.  So, given that you can
> either refer to the function this way:
>
> var foo = bar() { ... bar ...}
>
>   or this way:
>
> function bar() { ... arguments.callee ... }
>
> ... it's not clear to me what advantage the latter has over the former
> (IE bugs aside, that is).  Anonymity itself doesn't seem to be a
> virtue.

Well, having had a few moments to think about it, I actually think I
can give you some examples of when arguments.callee works but not the
function name:

- Functions created by function declarations do not provide a separate
inner name, and as such are subject to potential name rebinding,
especially with the shared global object between separate scripts.
- Functions created using "new Function(...)" do not have an inner
name. (Well, some implementations use the name "anonymous", some use
the name "anonymous" and assigns it as a local variable so that it
actually can be used this way and some don't name the function at
all.)
- Functions created using the string argument form of the setTimeout
and setInterval APIs.
- Functions created using HTML event handler attributes.
-- 
David "liorean" Andersson


More information about the Es-discuss mailing list