title: coffeeescript: how to declare private function that can be used from within Array.reduce?
body: <p>The main objective is to filter duplicate items from an array by any given property. The solution I'm trying to use is in js @ <a href="https://stackoverflow.com/a/31194441/618220">https://stackoverflow.com/a/31194441/618220</a></p>
  
  <p>I tried to implement it in coffeescript. It is all good, except the scoping of the functions. I don't want <strong>_indexOfProperty</strong> function to be called from outside - since it is useless in all other contexts. But if I make it <em>private</em> (by removing @ in declaration), I cannot call it from within <strong><em>inputArray.reduce</em></strong></p>
  
  <p>My coffee code looks like this:</p>
  
  <pre><code>Utils = -&gt;
      @filterItemsByProperty= (inputArray,property)=&gt;
          if not _.isArray inputArray
              return inputArray
          r = inputArray.reduce(((a,b,c,d,e)=&gt;
                  if @._indexOfProperty(a,b,property) &lt; 0
                      a.push(b)
                  a
              ),[])
          r
  
      @_indexOfProperty= (a,b,prop) -&gt;
          i = 0
          while i&lt; a.length
              if a[i][prop] == b[prop]
                  return i
              i++
          -1
  
      return
  
  window.utils = Utils
  </code></pre>
  
  <p>here's how I invoke it from other places:</p>
  
  <pre><code>App.utils.filterItemsByProperty(personArray,"name")
  </code></pre>
  
  <p>And right now, anyone can do this as well:</p>
  
  <pre><code>App.utils._indexOfProperty(1,2,3)
  </code></pre>
  
  <p>How to modify the coffee to stop this ?</p>