Sunday 15 March 2015

javascript - What does a plain old (function() { ... }) mean exactly? -


I have some javascript files that are set up in the Dropdown menus and they have everything written to ( Function () {...}) . I am thinking this is different from how it is not wrapped in an anonymous function. For example, how to

  $ ('# someElement'). Click (Warning ("Hi!")); Click  

inside any JS file other than

  (function () {$ ('# someElement') (alert ("Hi!") );});  

???

You can confuse it with this general syntax, as mentioned by others: / P>

  (function () {// code here} ());  

The first and the last brackets do nothing in this code, but it is used by people to avoid confusion. In other words, in other words, it creates an unknown function and runs it immediately, creating a local name space

Function Declaration is a syntax:
Function's Name (parameters) , Go here) {/ * code goes here} / /
It has been written as, it almost translates it:
nameGoesHere = new function ("parameter", " Go "," here "," / * code goes here / / ");
The only difference is that the function instance automatically detects its name when the function is written with the keyword .

When you type (function () {/ * Code here} /} ()); , you do not give a name to the function, so you actually do this: (new function (/ * here code * /) ()); . Let's return the returned function as the word "anonymous". This line becomes the (anonymous ()); , which executes the anonymous function and then you have been left with extra feet which were only there, so that it can be clear to read the code that it is the beginning of the closing .

If, on the other hand, you have seen:

  $ (function () {// code here});  

This adds a jQuery function which is added by jQuery, which executes the code in it when the page is fully loaded.


No comments:

Post a Comment