0
What is the significance of and reason for wrapping the entire content of a JavaScript source file in a function block??
2 Antworten
+ 4
So that you can recall it? wut?
+ 2
To avoid conflict problems when you run different scripts ( as if both use same name variable for different purpose ), and also limit the use of 'globals' variables... You declare an anonymized fonction as this:
(function(args) { })(param);
the declaration is placed in between parenthesis, and is executed with paremeters in second parenthesis pair, as soon as declarated...
Another reason for wrapping part of ( or entire ) code in function, is in case to need to delay execution ( typically for waiting the DOM be ready ) with declaring the function as soon as it's assigned to an event listener ^^