$(document).click(function(e) {
const $target = $(e.target);
let $itemsToClose = $('.top-menu__item');
if ($target.hasClass('top-menu__link')) {
const $item = $target.closest('li');
$item.toggleClass('top-menu__item_open').children('ul').slideToggle();
$itemsToClose = $itemsToClose.not($item);
}
$itemsToClose
.removeClass('top-menu__item_open')
.children('ul')
.slideUp();
});