Home

function: overArgs


overArgs(func: function, transforms: Array.): function

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

Example(s):

function doubled(n) {
  return n * 2
}

function square(n) {
  return n * n
}

const func = overArgs((x, y) => [x, y], [square, doubled])

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

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

Params:

Name Type Attribute Description
func The function to wrap.
transforms The argument transforms.

Returns:

function

  {
    "comment": "/**\r\n * Creates a function that invokes `func` with its arguments transformed.\r\n *\r\n * @since 4.0.0\r\n * @category Function\r\n * @param {Function} func The function to wrap.\r\n * @param {Function[]} [transforms=[identity]]\r\n *  The argument transforms.\r\n * @returns {Function} Returns the new function.\r\n * @example\r\n *\r\n * function doubled(n) {\r\n *   return n * 2\r\n * }\r\n *\r\n * function square(n) {\r\n *   return n * n\r\n * }\r\n *\r\n * const func = overArgs((x, y) => [x, y], [square, doubled])\r\n *\r\n * func(9, 3)\r\n * // => [81, 6]\r\n *\r\n * func(10, 5)\r\n * // => [100, 10]\r\n */",
    "meta": {
        "range": [
            574,
            902
        ],
        "filename": "overArgs.js",
        "lineno": 29,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100006613",
            "name": "overArgs",
            "type": "FunctionDeclaration",
            "paramnames": [
                "func",
                "transforms"
            ]
        },
        "vars": {
            "funcsLength": "overArgs~funcsLength",
            "": null
        }
    },
    "description": "Creates a function that invokes `func` with its arguments transformed.",
    "since": "4.0.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Function",
            "value": "Function"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "The function to wrap.",
            "name": "func"
        },
        {
            "type": {
                "names": [
                    "Array."
                ]
            },
            "optional": true,
            "defaultvalue": "[identity]",
            "description": "The argument transforms.",
            "name": "transforms"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "Returns the new function."
        }
    ],
    "examples": [
        "function doubled(n) {\r  return n * 2\r}\r\rfunction square(n) {\r  return n * n\r}\r\rconst func = overArgs((x, y) => [x, y], [square, doubled])\r\rfunc(9, 3)\r// => [81, 6]\r\rfunc(10, 5)\r// => [100, 10]"
    ],
    "name": "overArgs",
    "longname": "overArgs",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000616",
    "___s": true,
    "filepath": "overArgs.js"
}