Is there an jQuery equivalent of MooTools Hash?

ⅰ亾dé卋堺 提交于 2020-01-04 13:44:29

问题


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?


回答1:


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 :)




回答2:


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!




回答3:


Late for this post, but for anyone who finds this now, there is a plugin which describes itself as "The MooTools's Hash (from mootools-more) object/native for jQuery".

https://github.com/gcoguiec/jquery-hash



来源:https://stackoverflow.com/questions/2248728/is-there-an-jquery-equivalent-of-mootools-hash

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!