name property for built-in functions??

Allen Wirfs-Brock Allen.Wirfs-Brock at
Sun Mar 1 10:28:44 PST 2009

From: Brendan Eich [mailto:brendan at] 
>What should (new Function).name or (equivalently) Function().name return? Precedent in some engines:
>js> (new Function).name
>An anonymous function expression returns the empty string in some implementations:
>js> (function(){}).name
>js> typeof (function(){}).name
>js> (function(){}).name.length 

I have a hard time buying (new Function).name === "anonymous" when (function(){}).name==="".  I think it is fine to have the name distinguish functions created using new Function from functions created via function expressions that don't have an explicit name.  However, the concept of "anonymous" could reasonably be applied to either so using it for only one of them is likely to create confusion for programmer to don't deeply understand this difference. Plus, "anonymous" could actually be the declared name of a function.

In addition, at the Mt. View meeting we decide that if the target function of a bind call has the empty string as its name then the name of the function that is return from the bind is "bind anonymous function".  That would add to the confusion.

While it may go against precedent I think it would be more useful if (new Function).name === "new Function".  I can live with (function(){}).name==="" although (function(){}).name==="anonymous function" would probably be better.

More information about the Es-discuss mailing list