You actually already do this.
What he suggests is to wrap the entire script in a function like this:
function () { }
It's all. Nothing special. Of course, in regular javascript, a function definition simply defines a function, and the code inside the function does not run. Therefore, to automatically run a function, you transfer it to the context of the expression and call it:
(function () { })()
However, in node.js you do not need to do this. Instead, you can simply call the function when you need a module. So in node.js, this does the same in terms of creating a private scope:
module.exports = function () { }
So, tell your friend that you are already completing the entire script in the function.
This is perhaps the first time that I see harm in the name of things and design templates. In this case, your friend is thinking about IIFE. But IIFE is nothing special. IIFE does not create a closed area. It performs the functions that create the area. IIFE is just a means for a function to call itself. That is why I prefer to call it a self-service function, so as not to give it a sense of magic that can make some people perceive it as something special.
source share