Home

function: once


once(func: function): function

Creates a function that is restricted to invoking `func` once. Repeat calls to the function return the value of the first invocation. The `func` is invoked with the `this` binding and arguments of the created function.

Example(s):

const initialize = once(createApplication)
initialize()
initialize()
// => `createApplication` is invoked once

Params:

Name Type Attribute Description
func The function to restrict.

Returns:

function

  {
    "comment": "/**\r\n * Creates a function that is restricted to invoking `func` once. Repeat calls\r\n * to the function return the value of the first invocation. The `func` is\r\n * invoked with the `this` binding and arguments of the created function.\r\n *\r\n * @since 0.1.0\r\n * @category Function\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 * const initialize = once(createApplication)\r\n * initialize()\r\n * initialize()\r\n * // => `createApplication` is invoked once\r\n */",
    "meta": {
        "range": [
            579,
            629
        ],
        "filename": "once.js",
        "lineno": 19,
        "path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
        "code": {
            "id": "astnode100006511",
            "name": "once",
            "type": "FunctionDeclaration",
            "paramnames": [
                "func"
            ]
        }
    },
    "description": "Creates a function that is restricted to invoking `func` once. Repeat calls\rto the function return the value of the first invocation. The `func` is\rinvoked with the `this` binding and arguments of the created function.",
    "since": "0.1.0",
    "tags": [
        {
            "originalTitle": "category",
            "title": "category",
            "text": "Function",
            "value": "Function"
        }
    ],
    "params": [
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "The function to restrict.",
            "name": "func"
        }
    ],
    "returns": [
        {
            "type": {
                "names": [
                    "function"
                ]
            },
            "description": "Returns the new restricted function."
        }
    ],
    "examples": [
        "const initialize = once(createApplication)\rinitialize()\rinitialize()\r// => `createApplication` is invoked once"
    ],
    "name": "once",
    "longname": "once",
    "kind": "function",
    "scope": "global",
    "___id": "T000002R000608",
    "___s": true,
    "filepath": "once.js"
}