I would like to pass a comparer into a function and not sure if this is possible with Javascript. There is an IComparer concept in C# that does this. Can this be done in Javascript?
function someAction (comparer) {
var newList = [];
$.each(list, function (index, item) {
if comparer on item is true then { //psuedo code
newList.push(item);
}
});
}
someAction(item.PropA > 5);
function someAction (comparer) { var newList = []; $.each(list, function (index, item) { if (comparer(item)) { newList.push(item); } }); } someAction(function (item) { return item.PropA > 5 });PS: as @BrokenGlass suggested, you can avoid reinventing the wheel and use the
filterfunction.