I would like to know if it's possible to pass a method/property as a parameter in JavaScript.
An example of this would be something like this:
function uniq(list, property) {
var flags = [], output = [], l = list.length, i;
for (i = 0; i < l; i++) {
if (flags[list[i].property]) continue;
flags[list[i].property] = true;
output.push(list[i].property);
}
return output;
}
Is it possible to do such a thing? I'm in the process of trying to read through a single list of objects but have quite a few methods that will read through this list, just with very similar methods so I wish to eliminate a bit of redundancy.
I've tried passing the property name as a string but obviously that has thrown back an error.