从Javascript中的字符串生成哈希

我需要将字符串转换为某种形式的散列。这在JavaScript中可能吗

我没有使用服务器端语言,所以我不能这样做

String.prototype.hashCode=function(){
var hash=0,i,chr;
if(this.length==0)返回哈希;
对于(i=0;i<this.length;i++){
chr=这个charCodeAt(i);
哈希=((哈希<<5)-哈希)+chr;
hash |=0;//转换为32位整数
}
返回散列;
};

资料来源:
http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/

发表评论