What's the difference between
$(function() { // bind some event listeners });
and
$(function() { // bind some event listeners }());
In the above case, the function is passed in jquery, which will be executed after the document is ready.
In the above case, the return of the function is passed to jquery. Since the se3lf function is executed by itself, it will be executed immediately, and everything that the function returns will be passed to jquery, so this is not a good way, since the goal is to execute the function when the document is ready, which does not happen in this case
$(function(){...}); OR $(document).ready(function(){ ... });
, DOM , , , ..ready() , , DOM .
(function(){ ... })();
, , , JavaScript. , DOM .
, DOM , :
$(document).ready(function(){ // Write code here });
, $() self invoking. , .
$()
$(function() { ... });
jQuery :
$(document).ready(function() { ... });
The expressed instant expression of the function (or IIFE), instead, is the expression "immediately executed", the agreement is enclosed in parentheses, but each kind of expression is executed immediately, see the following IIFE functions:
(function() { console.log("IIFE 1"); }()); +function() { console.log("IIFE 2"); }(); 1-function() { console.log("IIFE 3"); }(); var f = 50 * function() { console.log("IIFE 4"); }();
Hope this was clear for now.
Source: https://habr.com/ru/post/1674733/More articles:Viper Architecture Routing - iosNested selection for multiple conditions - vbaHow to maintain a sticky session (session persistence) with docker? - dockerHow to return input values from callModule function in brilliant - rTesting WCF API with path parameters in Postman - apifetracking iOS camera (Swift 3 Xcode 8) - iosнамерение к конкретному действию при нажатии push-уведомления. - androidFull screen without navigation and status bars - androidPython PID not equal 1 - pythonget picasso image based on userId firebase - androidAll Articles