Skip to content Skip to sidebar Skip to footer

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"