Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
159 views
in Technique[技术] by (71.8m points)

javascript - Is there any other use of naming a function that is being assigned other than recursive calling itself?

If I say:

let F = function G(){}

What is destination of identifier G?

Is there any other reason to name it other than use it for recursion?

Is there a way that I could access identifier G?

question from:https://stackoverflow.com/questions/65929825/is-there-any-other-use-of-naming-a-function-that-is-being-assigned-other-than-re

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The name of functions is shown in the stack trace, if there is an exception thrown.

enter image description here

The name will typically also be shown in the debugger's scope window:

enter image description here

For these two reasons, naming anonymous functions can make debugging easier, especially when dealing with complex call structures with many anonymous functions.

If for some reason, you want to access the name of the function, you can do so with F.name


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...