This is extremely hard for me to explain in the title so I am just going to give an example to explain better:
I want to pass a function such as ()=>{console.log(this.operatorValue)}, as a parameter to recursive traverseCriteria function.
traverseCriteria Function
function traverseCriteria(arr, parameters,fn) {
for (const item of arr) {
if (Array.isArray(item))
this.traverseCriteria(item, parameters)
else if (typeof item === 'object'){
item.operatorValue = parameters[item.Property]
console.log(item.operatorValue) ///<-- REPLACE THIS WITH fn()
//fn()
}
}
return arr
}
In the above function I want to be able to replace console.log(item.operatorValue) with fn();
const criteria = [
"and",
{
"Collection": "persons",
"Property": "phone",
"operator": "eq",
"operatorValue": "23138213"
},
{
"Collection": "persondetails",
"Property": "country",
"operator": "eq",
"operatorValue": "Russia"
}
]
const parameters = { phone: "23138213", "country": "Russia" };
function call:
traverseCriteria(criteria,parameters,()=>{console.log(this.operatorValue)});