This function returns a hash code (MD5) based on the argument object. Please note that this implementation have some limitations (or features):

  • Two instances of the same "Class" with the same internal state return the same hash code, i.e. they are equal:
    HashCode.value(new Object(arg)) === HashCode.value(new Object(arg)) // is True
    
    // but...
    
    function MyClass(value) {
        this.value = value;
    }
    
    c1 = new MyClass(99);
    c2 = new MyClass(99);
    
    HashCode.value(c1) === HashCode.value(c2); // is True
    c1 === c2; // is False
  • 1 and 1.0 return the same code.
  • x143 and 99 return the same code.
For the hash code generation this script search for object types, names and values.

Powered by the Webtoolkit MD5 library.

How to use it

The following code shows how to use the HashCode.value() function.

var object1 = [];
var object2 = { f1 : function() { var i; }, a : [1, 2, "#", { m : function() { return 1; } }]};
var object3 = object2;
var object4 = function(arg) { arg++ };
var object5 = function(arg) { arg++ }(2);
var object6 = (function(arg) { arg++ })(2);

HashCode.value(object1); // result: d41d8cd98f00b204e9800998ecf8427e
HashCode.value(object2); // result: e72b9ba8d4c160ab0d1b2a828359dde1
HashCode.value(object3); // result: e72b9ba8d4c160ab0d1b2a828359dde1
HashCode.value(object4); // result: 16619c0e50afd2695fc1a22dab652395
HashCode.value(object5); // result: be36fcbc3ab6342a7cbcb2e37d2ae78f
HashCode.value(object6); // result: be36fcbc3ab6342a7cbcb2e37d2ae78f

Source code and examples

All the source code and examples are online here.