mishe / blog

前端碰上的问题或体会
230 stars 39 forks source link

tools:uniqID唯一ID的应用 #68

Open mishe opened 8 years ago

mishe commented 8 years ago

唯一ID

唯一ID的需求非常多,很多类库都有类似的函数,来实现这个唯一性;

但在前端方面,很难有真正意义上的唯一性,只能来尽量的降低重合几率。

下面的看看我这边的唯一ID的函数源码

 uniqID: function (string) {
        string = string || '';
        return string + Math.random().toString(36).substr(2, 10);
    },