Most of us have used JavaScript. In recent years, the popularity of various JavaScript frameworks has made JavaScript more magical and easier. "Anonymous function? I don't know what it is but it looks similar to what I wrote."
You may not know that you can construct a JavaScript function by passing a string as the body of the function to new Function() . It is not often used in programming, but sometimes it can be very useful.
The following is the basic usage of new Function:
The question is: When is it appropriate to use this method instead of using the traditional function declaration function myFnName() and/or anonymous function definition? Andrea Giammarchi believes that the most suitable scenario for using this method of function definition is in NodeJS and In the global environment of the browser: