Underscore.JS uniqueId 方法 语法 _.uniqueId([prefix])JavaScriptCopy uniqueId方法会生成一个唯一的id,如其名所示。如果传递了前缀,那么前缀将会附加到该id上。请看下面的示例: 示例 var _ = require('underscore'); // Example 1 var uniqueId1 = _.uniqueId("text"); // Example 2 var uniqueId2 = _.uniqueId("text"); console.log(uniqueId1); console.log(uniqueId2);JavaScriptCopy 将上述程序保存在 tester.js 中。运行以下命令来执行该程序。 命令 >node tester.jsJavaScriptCopy 输出 1 4 9 16 25JavaScriptCopy