Message from JavaScript discussions

November 2020

— Was making some infinite thing, then, read some Babich man

Message permanent page


He says infinite won't be effective for e-shop catalog, anyway i did some thing but he's mostly right

— I found this one very useful

— Https://

— Hi,
What are some strategies to get rid of circular dependencies

— Dependency injection

— Is there an example you can provide?

— By moving all your dependencies into the function signature, you can resolve the dependencies top-down from the root of your application. I've written in-depth about this here:

Message permanent page

— Let me check that out

— Not only do you avoid recursive dependencies, but you also open up to a lot of other flexibility goodies.. Like testing (mockability), you can wrap dependencies to your liking to add more functionality (e.g. a logger attached to fs.writeFile calls) there are many possibilities. It might look like a bit too much code, but you will soon appreciate the flexibility.

Message permanent page

— It works like that:

// index.js
const dependencies = {
a: require('./a'),
b: require('./b'),

// a.js
module.exports = dependencies => ({
getFile: () => 'filename',
save: () => {


// b.js
module.exports = dependencies => ({
whatever: () => dependencies

Message permanent page

— This is better viewed here: