The Drupal alternate better method to add jQuery

We usually add

$(document).ready(function () {
  // Do some fancy stuff.
});

However in drupal 8 we have better method.

function ($, Drupal) {
  Drupal.behaviors.changePathSettings = {
    attach: function (context, settings) {
      $(context).find('.layout-region-node-secondary details').once('details').attr('open', 'true');
    }
  };
})(jQuery, Drupal);

Tags: