why not
const $ = s => document.querySelectorAll(s);
const hide = e => e.style.display = 'none';
$('.submenus').forEach(hide);
or, if you're okay with changing prototypes const $ = s => document.querySelectorAll(s);
NodeList.prototype.hide = function () {this.forEach(e => e.style.display = 'none');};
$('.submenus').hide();