Pros And Cons Of Various Function Scopes/Event Binds In JavaScript/jQuery
What are the pros and cons of the following function scopes: Global Function/Inline JS
Solution 1:
I think the big argument to not use global variables comes with the nature of web collaboration. If you're build a site-wide script, and you have a team of lets say two others working on plugins, you don't want your variables to be overwritten or invoked by your collaborators. Additionally, having people consistently asking you to provide them with a list of your program variables and functions is going to slow everything down.
/* Private namespace */
(function () {
var sum_1 = 10;
var sum_2 = 20;
var myFunction = function (x, y) {
return x * y;
};
myFunction(sum_1, sum_2);
})();
Post a Comment for "Pros And Cons Of Various Function Scopes/Event Binds In JavaScript/jQuery"