I am working on an existing project that has been encoded by some developers that I don’t know. Surfing on javascript files, I see that they use this particular notation for the define function:
var ModuleScripts = (function() { return { init: function(){...} }; }())
Note in parenthesis function(){...}(). This code works fine, but when I want to write something, I use this notation:
function(){...}()
var ModuleScripts = function() { return { init: function(){...} }; }()
My code is working fine. So my question is: is there any good reason to use parentheses surrounding function(){...}()JavaScript?
Of the instant expression function :
-, , .
IIFE, ModuleScripts init(). IIFE ModuleScripts - , ! IIFE , , , , .
(!) IIFE, , , IIFE . , , . .
IIFE :
(function() { // the code here is executed once in its own scope })();
:
IFFE
(function x(){})()
( function x(){}() )
Source: https://habr.com/ru/post/1619523/More articles:Invalidation of swagger documentation - javascriptИспользование окна WPF в качестве визуального шаблона перед печатью - c#Source without window / gui - linuxprerequisites needed when moving from angular 1 to angular 2 - javascriptexit / b does not work correctly when inside a block with other commands - windows-7Python - decreases value - pythonLaravel Подтверждение ввода кнопки радио - phpAzure SQL Database TLS Handshake database error failed since v12 update - goFailed to load the application or run the command "Microsoft.AspNet.Server.Kestrel". Available commands: web - linuxHow to change the font size of scientific notation in matplotlib? - matplotlibAll Articles