0

I am using the following bit of code to set a filter. I have ESLint configured and am getting the following issue: Assignment to function parameter 'preferredDays' no-param-reassign

I don't quite see the issue this might cause. Is there a better alternative to the way I have handled it ?

function setPreferredDays(preferredDays) {
  $(`#${IDS.PREFERRED_DAYS_VALUE} > button`)
    .removeAttr('aria-selected');

  if (!preferredDays) {
    preferredDays = [1, 2, 3, 4, 5];
  }

  preferredDays.forEach(preferredDayValue => {
    $(`#${IDS.PREFERRED_DAYS_SELECTION}`)
      .find(`button[value= ${preferredDayValue} ]`)
      .attr('aria-selected',
        'true');
  });
}
ValyriA
  • 157
  • 2
  • 9
  • ESLint is configurable. If you have no problem with mutating a parameter value, then you can disable that setting. –  Sep 07 '16 at 17:18
  • 2
    Did you [read the page on the rule](http://eslint.org/docs/rules/no-param-reassign)? It's fairly clear about why some (many?) believe it's a bad idea. – T.J. Crowder Sep 07 '16 at 17:19
  • Hmm, isn't this more of a Stack Programmers question? Why is it a bad idea to mutate objects? – Tim Grant Sep 07 '16 at 17:20
  • @Juhana: Yeah. Different language, but this isn't really language-specific anyway (within the general language family JavaScript and Java both belong to, anyway). – T.J. Crowder Sep 07 '16 at 17:21
  • 1
    Reassigning a parameter variable is not as half as bad as mutating a passed in object. – Bergi Sep 07 '16 at 17:33
  • @T.J. The reassignment is only visible within the function body. It is "encapsulated" so to speak. This shouldn't be a problem at all. –  Sep 07 '16 at 18:36
  • @ftor: Where do you see me saying it is? In fact, my answer to the linked duplicate starts with *"For me, as long as you do it early and clearly, it's fine."* – T.J. Crowder Sep 08 '16 at 05:44

0 Answers0