我需要创建一个将传递给我的数据库服务器的函数。返回的函数将单个项目作为参数并将该项目与需求列表进行比较。
为此,我需要一个函数生成函数,该函数将数组作为参数并返回内置该数组的内部函数。
这是一个例子:
function create_query (list_of_requirements) {
return function (item) {
var is_match = true
// the next function sets is_match to false if the item fails
list_of_requirements.forEach(check_if_item_meets_requirement)
return is_match
}
}
一个使用这个的例子:
function search (parsed_user_string) {
db.get(create_query(parsed_user_string)).then(function(results){
show_results(results)
})
}
如何将需求列表构建到内部函数中?