Duplicate JavaScript names. Is it really bad?

As several developers work on javascript files, many of them have written the same file names over and over again.

A simple example would be getCookie, a setCookie type function.

Now we are doing aggregation in javascript files, will there be any problem if they have the same functions twice.

Now everything is working fine, but I want to know

Appreciate your help

+3
source share
3 answers

Yes, there will definitely be a problem if you end up with a function that is inadvertently defined twice in the global namespace. The function that was last defined will simply overwrite the previous one.

. JavaScript :

var myNamespace = (function () {
   var _name = 'Bob';

   return {
      somePublicMethod: function () {
         return 'Hello, ' + _name;
      }
   };
})();

alert(myNamespace.somePublicMethod());
+11

The Highlander — !

+5

, .

, ! , , .

0

Source: https://habr.com/ru/post/1775717/


All Articles