How can one pass a variable to a filter function in javascript?
In this case I’m trying to pass a value to variable “maxage”:
var dateFilter = function(value,maxage) { // Age in miliseconds
if(Date.now() - value < maxage) {
return value;
} else {
return false;
}
}
dates.filter(dateFilter,500);
How can I pass the value 500 to the filter as maxage?
You would need to invoke
Function.prototype.bindto create something similar to a default argument.dateFiltercallback would then called with500PLUS “automatic passed in values”value, index, array.