Skip to content

How to avoid "Assignment to property of function parameter 'elem'" #1653

@darde

Description

@darde

Hi guys, I want to understand how you guys avoid the eslint warning "Assignment to property of function parameter 'elem'". I know that is a good pattern do not change function parameters values. This keeps our code decoupled and with high maintenance. However, in some cases, I come across with the following situation.
I need to retrieve all elements with a specific class, and then, change its display style property.
This is my code:

const setDisplayStyleToElementsArray = (arr, display) => {
  arr.map((elem) => {
    elem.style.display = display;
    return elem;
  });
};

const elements = document.getElementsByClassName('.myClass');

const myFields = [].slice.call(elements, 0);

setDisplayStyleToElementsArray(myFields, 'block');

In this case, I'm changing the property "style" of all my .myClass elements. What is the correct way of doing that? How would airbnb development team handle such case?

Thanks in advance

Pablo Darde
front end engineer

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions