关于以下模拟代码(_与lodash库有关):
var containerFunction = function () {
var opts = {data: value};
_.map(lines, functionForEach);
}
var functionForEach = function (line) {
Do something for each line passed in from the maps function.
Need to access opts in this scope.
return value;
}
Run Code Online (Sandbox Code Playgroud)
参数行是从map函数接收的,但是将opts参数传递给functionForEach函数同时保持粗略模式(如果可能)的最佳方法是什么.
我想的是:
_.map(lines, functionForEach(opts))
Run Code Online (Sandbox Code Playgroud)
或类似的东西可能有效,但显然不是.
有什么建议?