0

For example, I working with a framework that would invoke a custom function like this:

var ret = Module_Init(index, clk, obj);

The function Module_Init should be defined by user. And in my Module_Init, I only need the first parameter index. So I define it like this:

function Module_Init(index)
{
    m_Index = index;
    // initialize code...
}

It work, but is it a good practice in Javascript?

Koen
  • 311
  • 2
  • 11
  • It's not good practice to pass unused arguments, you could confuse other developers reading your code. This also leads to a messy codebase. Get rid of them if you don't need then. – Dan Starns Apr 19 '20 at 07:11
  • 1
    IMO it doesn't really matter. There aren't any downsides to doing that, and the code is simpler to follow if only slightly. BTW you made a typo on `Index` – user120242 Apr 19 '20 at 07:11
  • 2
    @DanStarns Since the *framework* is invoking it, I think it's fine. You don't worry about the parameters you often don't use when using `Array.prototype.forEach` either – CertainPerformance Apr 19 '20 at 07:12
  • @CertainPerformance my point is, you don't need to declare them in your code. – Dan Starns Apr 19 '20 at 07:13
  • 1
    I can't really decide if this is one of those questions that should be closed, because the answer really comes down to opinion rather than a concrete indisputable fact. Especially because I think the question about style is a valid and useful one. – user120242 Apr 19 '20 at 07:15
  • Voted to close as this really is opinion based. Perhaps [*Currying*](https://stackoverflow.com/questions/113780/javascript-curry-what-are-the-practical-applications) is a better approach. – RobG Apr 19 '20 at 07:35
  • @user120242 Fixed typo. Thanks :D – Koen Apr 20 '20 at 04:27

1 Answers1

0

If you are not going to use them, why put them in the function

nastari
  • 51
  • 6
  • The framework pass these parameters. User need to define the function accordingly. But user don't need use all these parameters passing by framework in my case. Thanks. – Koen Apr 20 '20 at 04:22