// 生成 guid 的方法 function guid() { return ‘xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx‘.replace(/[xy]/g, function(c) { var r = Math.random()*16|0, v = c == ‘x‘ ? r : (r&0x3|0x8); return v.toString(16); }); } console.log(guid()); //=> 3b7f5469-6880-4f04-97cc-f57e3711ab99 console.log(guid()); //=> 0067400f-1562-4b7c-837f-8ab06137b39a console.log(guid()); //=> 91cd58f6-1c29-47d5-8204-a5c519713fe9 console.log(guid()); //=> 693231e2-7341-4f26-a069-c91fd0263710