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

uniqueId.js 562B

12345678910111213141516171819202122232425262728
  1. var toString = require('./toString');
  2. /** Used to generate unique IDs. */
  3. var idCounter = 0;
  4. /**
  5. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  6. *
  7. * @static
  8. * @since 0.1.0
  9. * @memberOf _
  10. * @category Util
  11. * @param {string} [prefix=''] The value to prefix the ID with.
  12. * @returns {string} Returns the unique ID.
  13. * @example
  14. *
  15. * _.uniqueId('contact_');
  16. * // => 'contact_104'
  17. *
  18. * _.uniqueId();
  19. * // => '105'
  20. */
  21. function uniqueId(prefix) {
  22. var id = ++idCounter;
  23. return toString(prefix) + id;
  24. }
  25. module.exports = uniqueId;