您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

once.js 665B

12345678910111213141516171819202122232425
  1. var before = require('./before');
  2. /**
  3. * Creates a function that is restricted to invoking `func` once. Repeat calls
  4. * to the function return the value of the first invocation. The `func` is
  5. * invoked with the `this` binding and arguments of the created function.
  6. *
  7. * @static
  8. * @memberOf _
  9. * @since 0.1.0
  10. * @category Function
  11. * @param {Function} func The function to restrict.
  12. * @returns {Function} Returns the new restricted function.
  13. * @example
  14. *
  15. * var initialize = _.once(createApplication);
  16. * initialize();
  17. * initialize();
  18. * // => `createApplication` is invoked once
  19. */
  20. function once(func) {
  21. return before(2, func);
  22. }
  23. module.exports = once;