M
M
Mikhail2017-03-05 13:54:50
Node.js
Mikhail, 2017-03-05 13:54:50

Is it okay to "simplify" the code this way?

Hello. I am writing a telegram bot. Now the code looks something like this:

bot.on('message', msg => {
   someFunc(bot, redis, db, msg)
});

function someFunc(bot, redis, db, msg) {
  //какие-то действия с Redis
  //какие-то действия с БД
  bot.sendMessage(msg.from.id, 'TExt');
}

I don't like that I'm passing a lot of variables to the someFunc function (the number of these variables will increase over time). And I decided to use a closure:
function gen(bot) {
   return send(id, text) {
       bot.sendMessage(id, text)
   }
}

Now I don't need to pass the bot variable to someFunc. Instead, I will call the send() function. Is this normal practice? Won't this worsen the readability and maintainability of the code?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Damir Makhmutov, 2017-03-05
@mak_ufo

This is called "carrying".
Quite normal practice.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question