A new function name property proposal

Jorge Chamorro jorge at jorgechamorro.com
Fri Nov 23 16:48:51 PST 2012

On 23/11/2012, at 18:47, Brendan Eich wrote:
> Jorge Chamorro wrote:
>> On 22/11/2012, at 09:38, Brendan Eich wrote:
>>> Right. I think Jorge may be concerned that naming a function does not always relieve the "need" for arguments.callee. But that's only true in a function declaration, which is inherently named, as you showed -- and only if one then overwrites the name in its scope.
>>> So don't do that. Fear that someone else might means you are in the global scope, which means that instead of using such a hard case to justify arguments.callee, you ought to modularize with an IIFE or (in due course) ES6 module.
>> To clarify, I wasn't trying to justify arguments.callee.
>> "don't do that" is a solution, for this and for many other WTFs and footguns...
>> But, isn't the NFEs' way the Right Way to do it?
> Do what?

Bind the name inside the function *too*.

> Function declarations are useful too. They hoist so you can write them in top-down order and call in any order from top-level code.

And hoisting is handy, I use it a lot and can't live without it.

> You can't do this with vars initialized with function expressions.

Of course, if they were interchangeable we'd simply write var x= function x () {}; and done.

>> Do we want this footgun in function declarations?
> What footgun?

The footgun (1) is to have the name bound *only* in the outer scope.

> People don't overwrite function declarations' bindings by accident much, if at all.
> I can't remember hearing of this lately, although it can happen when loading libraries where a common name is used by two libraries.

Yes it's a corner case.

> Programmers do intentionally replace a function's name in its scope, e.g. to auto-memoize.

Oh, how does that work? I've written memoizers but never needed to overwrite a name.

>> Why?
>> Is there any reason for not removing it? (Other than "because it's a corner case"?)
> Removing what?

The footgun (1)

> The writable binding created by a function declaration? That's required by backward compatibility (e.g. the memoization pattern).

The -outer- writable binding isn't the problem, the problem is the lack of binding in the inner scope. Is there a reason for not having it?

More information about the es-discuss mailing list