From: Brendan Eich [mailto:[email protected]]
>What should (new Function).name or (equivalently) Function().name return?
>Precedent in some engines:
>
>js> (new Function).name
>anonymous
>
>An anonymous function expression returns the empty string in some
>implementations:
>
>js> (function(){}).name
>
>js> typeof (function(){}).name
>string
>js> (function(){}).name.lengthÂ
>0
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.
_______________________________________________
Es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss