Drupal.behaviors, attach and origin of it
The attach() and detach() methods are part of the Behaviors interface defined by Drupal:


  Any object defined as a property of Drupal.behaviors will get its
  attach() method called when the DOM has loaded both initially and
  after any AJAX calls.


https://www.drupal.org/docs/8/api/javascript-api/javascript-api-overview