I have a method which\'s main purpose is to set a property on a DOM object
function (el) {
el.expando = {};
}
I use AirBnB\'s code style
The no-param-reassign
warning makes sense for common functions, but for a classic Array.forEach
loop over an array which you intend to mutate it isn't to appropriate.
However, to get around this, you can also use Array.map
with a new object (if you are like me, dislike snoozing warnings with comments):
someArray = someArray.map((_item) => {
let item = Object.assign({}, _item); // decouple instance
item.foo = "bar"; // assign a property
return item; // replace original with new instance
});