So here a couple of things happen. Everything ends with an anonymous function that runs immediately. This is done to create a scope for the library, so when the author declares functions and variables, they are not global by default.
With me still. So, the next thing is the total ($){...}(jQuery)
thing. What happens here, the author passes the jQuery
library into an anonymous wrapper function as a parameter named $
. Therefore, as part of an anonymous function, it can use $
for jQuery
links, as one would expect. This is more suitable for practice, because 99% of the time jQuery is already defined as $
in the global scope, but its poor form refers to global variables within the scope of functions, and thus it passes it to as a parameter.
Yet? Exclamation mark: There is a rule in Javascript that says that the first line of a program MUST be an expression (i.e. Not a function declaration of aka). Adding! the author turns the declaration into an expression (which returns false). In this case, however, I do not think so! actually required because the declaration is wrapped in () and executed immediately. (A function call is an expression)
source share