Home

function: before


before(n: number, func: function): function

Creates a function that invokes `func`, with the `this` binding and arguments of the created function, while it's called less than `n` times. Subsequent calls to the created function return the result of the last `func` invocation.

Example(s):

jQuery(element).on('click', before(5, addContactToList))
// => Allows adding up to 4 contacts to the list.

Params:

Name Type Attribute Description
n The number of calls at which `func` is no longer invoked.
func The function to restrict.

Returns:

function

  {
    "comment": "/**\r\n * Creates a function that invokes `func`, with the `this` binding and arguments\r\n * of the created function, while it's called less than `n` times. Subsequent\r\n * calls to the created function return the result of the last `func` invocation.\r\n *\r\n * @since 3.0.0\r\n * @category Function\r\n * @param {number} n The number of calls at which `func` is no longer invoked.\r\n * @param {Function} func The function to restrict.\r\n * @returns {Function} Returns the new restricted function.\r\n * @example\r\n *\r\n * jQuery(element).on('click', before(5, addContactToList))\r\n * // => Allows adding up to 4 contacts to the list.\r\n */",
    "meta": {
        "range": [
            624,
            926
        ],
        "filename": "before.js",
        "lineno": 16,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100000178",
            "name": "before",
            "type": "FunctionDeclaration",
            "paramnames": [
                "n",
                "func"
            ]
        },
        "vars": {
            "result": "before~result",
            "": null
        }
    },
    "description": "Creates a function that invokes `func`, with the `this` binding and arguments\rof the created function, while it's called less than `n` times. Subsequent\rcalls to the created function return the result of the last `func` invocation.",
    "since": "3.0.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Function",
            "value": "Function"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "number"
                ]
            },
            "description": "The number of calls at which `func` is no longer invoked.",
            "name": "n"
        },
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "The function to restrict.",
            "name": "func"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "Returns the new restricted function."
        }
    ],
    "examples": [
        "jQuery(element).on('click', before(5, addContactToList))\r// => Allows adding up to 4 contacts to the list."
    ],
    "name": "before",
    "longname": "before",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000016",
    "___s": true,
    "filepath": "before.js"
}