P
P
profcat2019-09-28 23:43:04
JavaScript
profcat, 2019-09-28 23:43:04

How to organize multiple related modules?

Hey! Suppose there are 3 related files.
index.js second.js
let modules = require('./second.js');

let modules = require('./third.js');

function doSmth() {
  //do something
}

third.js Requirement: You need to make the index module just go through the second code and execute it, making export only for those functions that need to be exported to index. But doSmth(), for example, does not need to be exported to index. But in the third - it is vital. In short, doSmth should only be available to third. How to properly organize it? There was an idea to operate with the module object and its properties, but I can’t imagine how. Can you give me a push in the right direction?
let modules = require('./second.js');

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Max, 2019-09-29
@profcat

No way. You cannot make an exclusive import for a particular file. Here, either take away doSmth in third, or create fourth if you need to use it in both second and third, but then it will also be available for import into index

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question