From 0937237bfdc0a69be69a7ea9b7315ea0ca11949c Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Fri, 31 Aug 2012 13:56:29 +0200 Subject: [PATCH] Added .hashCode() for strings --- wcfsetup/install/files/js/WCF.js | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index 49694987a8..6b1146b42c 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -45,6 +45,26 @@ // Inspired by base2 and Prototype (function(){var a=false,b=/xyz/.test(function(){xyz})?/\b_super\b/:/.*/;this.Class=function(){};Class.extend=function(c){function g(){if(!a&&this.init)this.init.apply(this,arguments);}var d=this.prototype;a=true;var e=new this;a=false;for(var f in c){e[f]=typeof c[f]=="function"&&typeof d[f]=="function"&&b.test(c[f])?function(a,b){return function(){var c=this._super;this._super=d[a];var e=b.apply(this,arguments);this._super=c;return e;};}(f,c[f]):c[f]}g.prototype=e;g.prototype.constructor=g;g.extend=arguments.callee;return g;};})(); +/** + * Provides a hashCode() method for strings, similar to Java's String.hashCode(). + * + * @see http://werxltd.com/wp/2010/05/13/javascript-implementation-of-javas-string-hashcode-method/ + */ +String.prototype.hashCode = function() { + var $char; + var $hash = 0; + + if (this.length) { + for (var $i = 0, $length = this.length; $i < $length; $i++) { + $char = this.charCodeAt($i); + $hash = (($hash << 5) - $hash) + $char; + $hash = $hash & $hash; // convert to 32bit integer + } + } + + return $hash; +} + /** * Initialize WCF namespace */ -- 2.20.1