let a = function (b) {
document.querySelector(b).addEventListener("click", function (event) {
let target = event.target;
if (target = target.closest(".menu__name")) {
event.preventDefault();
let parent = target.parentNode;
let children = parent.parentNode.children;
[...children].forEach(el => el.classList[el === parent ? "toggle" : "remove"]("menu__item--active"))
}
});
}
a('.menu');
а так более правильно ?