I designed my library like this:

let name = (function() { 'use strict'; return { //То что нужно вынести }; })(); 

But I don’t really understand how iife works and don’t I understand it correctly?

  • it is not clear what she does, what the function is for ... And what is iife ? - Air
  • @Air functionality does not matter, IIFE is a construct (function () {}) () - user272575
  • For the first time I see such an abbreviation ... well, not the point ... but the question is, if the function does not matter, what is the question? - Air
  • @Air the question is that I want to find out how it is accepted to design them so as not to clutter up the namespace. - user272575
  • Read about CommonJS, AMD, UMD and to the heap ES6 imports - andreymal

1 answer 1

The problem is that this question cannot be answered unambiguously.

There are guidelines like this or idiomatic .

Different companies use their guidelines:

It would be useful to read such articles. But the choice is yours. I would recommend to look at popular js libraries and do it by analogy.

  • In this case, the design can be considered correct? - user272575 pm
  • @brachkoff I'm not working with client js. In nodejs this was not correct. - Suvitruf