Separating a Hash type from Object

Jason Orendorff jason.orendorff at gmail.com
Wed May 30 17:20:14 PDT 2007


On 5/29/07, Brendan Eich <brendan at mozilla.org> wrote:
> * key/value type parameterization, hashcode callback function
> parameterization
> * defaults to intrinsic::=== and intrinsic::hashcode for identity and
> hashing

OK, it strikes me as a little weird, now, to use intrinsic::=== and
intrinsic::hashcode() here.

Java, Python, and Ruby let individual *classes* (rather than individual
hash tables) override hash() and equals().  I think this supports
generic code better.

  function uniq(values) {
      var d : Dict = {};  // nothing special here
      for each (var v in values)
          d.put(v, true);
      return d.keys();
  }

Also, if I were distributing a JavaScript library, I would be happier
saying "you can use FooBar objects as hash table keys" than
"if you want to use a FooBar as a hash table key, you need to pass
these two magic functions to the Dictionary constructor when you
create the Dictionary: new Dictionary(FooBar.eq, FooBar.hash)".

-j



More information about the Es4-discuss mailing list