1

I have to make template modules, each of which has 3 functions. For example, there can be module1.js which will have exports.function1, exports.function2 and exports.function3. There will be module2.js which also has the exact same functions; just the functionality would differ.

I use WebStorm for development and when I type exports., it gives me the 3 function names as autocomplete suggestions.

My question is, will these functions overwrite each other? Or is it okay to have same function names in different modules?

An SO User
  • 24,612
  • 35
  • 133
  • 221
  • Possible duplicate of [Does JavaScript have the interface type (such as Java's 'interface')?](http://stackoverflow.com/questions/3710275/does-javascript-have-the-interface-type-such-as-javas-interface) – cshion Jul 23 '16 at 17:39

1 Answers1

1

There is no issue if you use the same name: exports is, at core, a simple object, and this is perfectly fine:

var obj = {a: 1};
var obj2 = {a: 2};
console.log(obj.a + obj2.a); // prints... 3!

The reason WebStorm shows the three functions is because it's unable to statically determine which are actually available. If you run the code, you'll confirm it.

An SO User
  • 24,612
  • 35
  • 133
  • 221
Ven
  • 19,015
  • 2
  • 41
  • 61