小编Seo*_*ixx的帖子

将其他参数传递给函数调用(lodash)

关于以下模拟代码(_与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)

或类似的东西可能有效,但显然不是.

有什么建议?

javascript scope lodash

3
推荐指数
2
解决办法
5167
查看次数

标签 统计

javascript ×1

lodash ×1

scope ×1