I am trying to bind in a var into some functions so i can have access to it in an inner function.
function checkIfIsFilter(currentfilters, parentSearch) {
for (var group of currentfilters) {
if (_.find(group.filters, {"search": parentSearch})) {
return group.parentSearch || group.name;
}
}
};
function checkIfSubtopic(currentfilters, memo, value, key) {
if (value.parentSearch) {
value.subtopicOf = checkIfIsFilter(value.parentSearch).bind(null, currentfilters);
}
memo[key] = value
return memo;
}
console.log(_.reduce(currentfilters, checkIfSubtopic.bind(null, currentfilters), {}));
This seems to break the functions, specifically at the value.subtopicOf = part with the error message of Cannot read property 'bind' of undefined. I just want to bring currentfilters into the inner most function so i can reference it. This was working fine when I have it as a global variable ( can just just reference currentfilters directly inside of the checkIfIsFilter function), but I will not be able to have it like that in production.
I have a fiddle here I've been working in : https://jsfiddle.net/0fttkyey/79/
Unsure what I am doing correctly, would appreciate any input. Thanks for reading!