UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

31 lines (30 loc) 950 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.once = void 0; const before_1 = __importDefault(require("./before")); /** * 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. * * @since 5.15.0 * @category Function * @param {Function} func The function to restrict. * @returns {Function} Returns the new restricted function. * @example * * ```ts * const initialize = once(createApplication) * initialize() * initialize() * // => `createApplication` is invoked once * ``` */ function once(func) { return (0, before_1.default)(2, func); } exports.once = once; exports.default = once;