Array.filter () method is not magic, it will only iterate the array and call a function for every record. Do not get me wrong - I'm a fan of elegant solutions, but what you're trying to do is nosense. What you do, it (this code is not tested for explanation);
function filterCondition(obj, arg1, arg2, arg3,.. ) { //TODO: define your individual filter logic } var filter = function(products, arg1, arg2, arg3,.. ) { var filtered = []; for (var i= 0, l = products.length; i < l; i++) { var product = products[i]; if (filterCondition(product, arg1, arg2, arg3,.. )) filtered.push(product); return filtered; } , arg3, ..) { function filterCondition(obj, arg1, arg2, arg3,.. ) { //TODO: define your individual filter logic } var filter = function(products, arg1, arg2, arg3,.. ) { var filtered = []; for (var i= 0, l = products.length; i < l; i++) { var product = products[i]; if (filterCondition(product, arg1, arg2, arg3,.. )) filtered.push(product); return filtered; } , arg2, arg3, ..) { function filterCondition(obj, arg1, arg2, arg3,.. ) { //TODO: define your individual filter logic } var filter = function(products, arg1, arg2, arg3,.. ) { var filtered = []; for (var i= 0, l = products.length; i < l; i++) { var product = products[i]; if (filterCondition(product, arg1, arg2, arg3,.. )) filtered.push(product); return filtered; } ; i ++) { function filterCondition(obj, arg1, arg2, arg3,.. ) { //TODO: define your individual filter logic } var filter = function(products, arg1, arg2, arg3,.. ) { var filtered = []; for (var i= 0, l = products.length; i < l; i++) { var product = products[i]; if (filterCondition(product, arg1, arg2, arg3,.. )) filtered.push(product); return filtered; } arg2, arg3, ..)) function filterCondition(obj, arg1, arg2, arg3,.. ) { //TODO: define your individual filter logic } var filter = function(products, arg1, arg2, arg3,.. ) { var filtered = []; for (var i= 0, l = products.length; i < l; i++) { var product = products[i]; if (filterCondition(product, arg1, arg2, arg3,.. )) filtered.push(product); return filtered; }
Using bind () is the function in an area that has been identified during the bind .. 1st argument. Therefore, if you need to bind this function, you can use it:
filter.bind(products, arg1, arg2, arg3,..);
But this means that the filter function is triggered in the array of products. Therefore, you need to change the settings:
var filter = function(arg1, arg2, arg3,.. ) { var filtered = []; for (var i= 0, l = this.length; i < l, i++) { var product = this[i]; if (filterCondition(product, arg1, arg2, arg3,.. )) filtered.push(product); return filtered; } , arg3, ..) { var filter = function(arg1, arg2, arg3,.. ) { var filtered = []; for (var i= 0, l = this.length; i < l, i++) { var product = this[i]; if (filterCondition(product, arg1, arg2, arg3,.. )) filtered.push(product); return filtered; } , i ++) { var filter = function(arg1, arg2, arg3,.. ) { var filtered = []; for (var i= 0, l = this.length; i < l, i++) { var product = this[i]; if (filterCondition(product, arg1, arg2, arg3,.. )) filtered.push(product); return filtered; } arg2, arg3, ..)) var filter = function(arg1, arg2, arg3,.. ) { var filtered = []; for (var i= 0, l = this.length; i < l, i++) { var product = this[i]; if (filterCondition(product, arg1, arg2, arg3,.. )) filtered.push(product); return filtered; }
btw: Jean-Francois used this at the entrance to the array .. it's not, it just looks a bit confusing