Make _.uniqueId consistently return a string value.

Former-commit-id: 5a5c626df83b0fc78e9bae37510680383f112c0b
This commit is contained in:
John-David Dalton
2012-11-29 22:17:00 -08:00
parent 529c5b8abf
commit 619ba13265
7 changed files with 165 additions and 134 deletions

View File

@@ -4008,22 +4008,23 @@
}
/**
* Generates a unique id. If `prefix` is passed, the id will be appended to it.
* Generates a unique ID. If `prefix` is passed, the ID will be appended to it.
*
* @static
* @memberOf _
* @category Utilities
* @param {String} [prefix] The value to prefix the id with.
* @returns {Number|String} Returns a numeric id if no prefix is passed, else
* a string id may be returned.
* @param {String} [prefix] The value to prefix the ID with.
* @returns {String} Returns the unique ID.
* @example
*
* _.uniqueId('contact_');
* // => 'contact_104'
*
* _.uniqueId();
* // => '105'
*/
function uniqueId(prefix) {
var id = idCounter++;
return prefix ? prefix + id : id;
return (prefix == null ? '' : prefix + '') + (++idCounter);
}
/*--------------------------------------------------------------------------*/