title: How to make JS function global in webpacker Rails 6
body: <p>I try to organise my frontend as I used to do in Rails 5. I had some js file with functions and used this functions in different places of code up to my needs. But in Rails 6 work with js is quite different. Anyway, I think I got the main idea about packs and webpacker. But how to use custom js functions? Write it in one file and use in another? There is should be the way to do it.</p>
  
  <p>For example, I have some custom js pack:</p>
  
  <p><strong>app/javascript/packs/custom_pack_with_functions.coffee</strong>:</p>
  
  <pre><code>console.log 'hey'
  
  @hi = () -&gt;
    console.log 'HI'
  </code></pre>
  
  <p>And I expect that <code>hi</code> function will be available in my view.</p>
  
  <p><strong>some_view.html.slim</strong>:</p>
  
  <pre><code>= javascript_pack_tag 'custom_pack_with_functions'
  
  javascript:
    hi()
  </code></pre>
  
  <p>But when I come to appropriate page, I see in console only following messages:</p>
  
  <pre><code>hey
  ReferenceError: hi is not defined
  </code></pre>
  
  <p>​
  How to define <code>hi</code> function to use it from anywhere?</p>