How to add extra eventlistener to menu object in attached library
Couple of problems. But the main two are:


In Drupal 8, you need to call $.each() on $.once()
In Drupal you don't need to call $.on() on elements. The combination of Drupal.behaviors and $.once() achieves the same goal.


So your code should be something like:

$(".navbar-collapse", context).once('myMainMenu').each(function () {
  // Do stuff here
});