title: Global function and method at the same time
body: <p>For example, I'm writing a function that uses two arrays. How can I define this function to call it as a global function, passing it two arrays or as an <code>Array</code> method, passing it a second array:</p>
  
  <pre><code>func([1, 2, 3], [3, 2, 1]);
  [1, 2, 3].func([3, 2, 1]);
  </code></pre>
  
  <p>Here is my idea:</p>
  
  <pre><code>func = function (...args) { // define global function
      if (args.length &gt; 1) { 
          // function called as global with 2 arrays in arguments
      } else {
          // function called as Array method, with second array in arguments
      }
  }
  Array.prototype.func = func; // define Array method
  </code></pre>
  
  <p>Is there a more better way?
  Thanks.</p>