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

Jon Zeppieri jaz at bu.edu
Thu Sep 11 12:11:30 PDT 2008


On Thu, Sep 11, 2008 at 2:34 PM, Brendan Eich <brendan at mozilla.org> wrote:

> In ES4 we proposed new syntax (that violate the holy Tennent) to get
> callee: |this function|. ES4 proposed to deprecate arguments by
> specifying only rest and optional parameters normatively, leaving
> arguments (which has never been fully specified to be web-compatible)
> to an informative annex.
>
> With 3.1 and Harmony we may have to keep arguments "more normative"
> but reform it in strict mode till it's vestigial, while adding rest
> and optional params. Sounds like a plan. But arguments.callee use
> cases deserve a look. They are out there, in great number.

I imagine the appeal of arguments.callee comes from the fact that it
allows programmers to rename functions without having to change
recursive calls within the body of the function.  Leaving aside the
matter of how onerous this renaming actually is, the ability to have
an outer, public name, as well as an inner, private one already exists
in ES3:

var foo = function bar(x) { ... bar(y) ... }

... works fine, so long as bar isn't shadowed in the function body.
The programmer can change the public name ("foo") to anything else
without worrying about breaking recursive call sites inside the
function.  (In this case, it happens to be considerably terser than
arguments.callee, too.)

Recursion isn't the only possibility here.  Higher-order use of the
callee -- i.e., returning it, passing it to another function -- is
also possible and is handled correctly by the idiom above.

Are there uses of arguments.callee that can't be handled this way?


More information about the Es-discuss mailing list