Skip to content

overArgs

js
_.overArgs(func, [transforms=[_.identity]])

创建一个函数,使用转换后的参数调用 func

¥Creates a function that invokes func with its arguments transformed.

新增于

¥Since

4.0.0

参数

¥Arguments

  1. func (函数):要调用的函数。

    ¥func (Function): The function to wrap.

  2. [transforms=[_.identity]] (...(函数|函数[])):参数转换。

    ¥[transforms=[_.identity]] (...(Function|Function[])): The argument transforms.

返回

¥Returns

(函数):返回新函数。

¥(Function): Returns the new function.

示例

¥Example

js
function doubled(n) {
  return n * 2;
}

function square(n) {
  return n * n;
}

var func = _.overArgs(function(x, y) {
  return [x, y];
}, [square, doubled]);

func(9, 3);
// => [81, 6]

func(10, 5);
// => [100, 10]

Lodash v4.17 中文网 - 粤ICP备13048890号