views:

301

answers:

2

I don't think jQuery has a Hash class, so is there an equivalent?

I always thought Object does a good job hashing stuff anyway. So what's special about the MooTool's hash besides some of its utility methods?

+3  A: 

i can't answer your question in full as i know next to nothing about jquery but i will try to explain hashes in mootools so you can try and locate an appropriate solution yourself

basically, the best part of the mootools hash is the ability to prototype objects so they can support/inherit common methods (which you can't do on a normal object).

for instance, the method that returns the object's keys through hash is var keys = new Hash({foo:'bar'}).getKeys();

so in addition to inheriting the built-in methods by the framework (http://mootools.net/docs/core/Native/Hash), you can define your own by prototyping the hash native through Hash.implement:

Hash.implement({
    ismoo: function() {
        return this.hasValue("moo");
    }   
});

var f = new Hash({foo:'moo',moo:'cow'});
alert(f.ismoo());

what i can't tell you is how to replicate such functionality in jquery - you can probably extend jQuery, i imagine through iirc $.fn.hasValue = function() { ... }; or whatever the syntax was.

anyway - bottom line is, mootools.Hash does not do anything you can't do yourself in a different way, it just does it conveniently well :)

Dimitar Christoff
+1  A: 

MooTools and jQuery aren't mutually exclusive.

Most of MooTools' general programming modules are simply out of the jQuery scope. jQuery is fully built to work well with other general programming tools and frameworks.

MooTools is very modular. You could easily build a custom MooTools build using MooTools' Core Builder with only Hash. I tried it out and it came in around 6k with YUI compression (even less with gzip).

If, for whatever reason, you want to completely rewrite your code to remove all traces of Hash, you could use the custom build as a stop-gap measure. Release early and release often!

subtleGradient