Javascript array filter() with bind()
<p>I'm using the filter() array helper going through some objects in an array. My idea is to create a dynamic filtering function to go through the objects in the array using bind(), but the arguments in bind are being used in a different way that I expected. Here's the code:</p>

<pre class="lang-js prettyprint-override"><code>var products = [
  {name:"lettuce", type:"vegetable"},
  {name:"apple", type:"fruit"},
  {name:"carrot", type:"vegetable"},
  {name:"orange", type:"fruit"}
];

// this is the function used in filter()
function filterProducts(cat, product){
  return product.type === cat;
}

// new array
var vegetables = products.filter(filterProducts.bind(products, "vegetable"));
</code></pre>

<p>I'm assuming that the filter helper is passing each object in the array after the arguments in the bind method, so first is the products which accounts for <code>this</code> in the callback, then is the type I want to check on each object and finally the object itself.</p>

<p>The question is: Would you recommend doing it like this? I mean, could this be considered a good practice or would it be better to create a function to filter each type instead of doing it like this?</p>