Javascript MooTools Hash/Object.jquery中的每个等价项

Javascript MooTools Hash/Object.jquery中的每个等价项,javascript,jquery,mootools,Javascript,Jquery,Mootools,在我的项目中,我需要将一个大脚本(表单验证插件)从mootools转换为Jquery。它有面向对象的概念。我搜索了很多,找到了HJS面向对象的Jquery插件并合并了,但在以下方面有问题 initialize : function (form, options){ if (this.form = $(form)) { this.form.isValid = true; this.regex = ['length']; this.alertMsg = []; this.


在我的项目中,我需要将一个大脚本(表单验证插件)从mootools转换为Jquery。它有面向对象的概念。我搜索了很多,找到了HJS面向对象的Jquery插件并合并了,但在以下方面有问题

initialize : function (form, options){
if (this.form = $(form)) {      
  this.form.isValid = true;
  this.regex = ['length'];
  this.alertMsg = [];
  this.validations = [];
 var regex = new Hash(this.options.regexp);
  regex.each(function(el, key) {
  this.regex.push(key);
}, this);
var alertMsg = new Hash(this.options.alerts);
  alertMsg.each(function(el, key) {
  this.alertMsg.push(key);
}, this);
$(form).find("*[class*=validate]").each(function(el) {          
   this.register(el);
}, this);
}
},
......
此.register(el)功能未触发

Jquery中的“newhash()”等价物是什么? 如何替换jquery中的函数(el)

请在这方面帮助我

谢谢,

HG

mootools中的Hash
类型基本上是一个原型对象克隆
类型
,可以安全地获得方法,如
。每个
。一些
,等等-

最终,您使用的是javascript,您可以使用对象中的var来遍历javascript中的对象

var object = {
    foo: "bar",
    bar: "foo"
};

for (var key in object) {
    alert(key);
    alert(object[key]);
}
需要考虑的事项:检查hasOwnProperty或在对象上设置
\uuuuu proto\uuuuu:null
,以避免出现以下问题:

Object.prototype.hello = "world";
var object = {
    foo: "bar",
    bar: "foo"
};

for (var key in object) {
    alert(key); // foo, bar, hello
    alert(object[key]);
}
相反,要:

var object = {
    __proto__: null,
    foo: "bar"
};
如果可用,它也可以用作新对象(空)


是的,对对象进行原型化不是一种安全的做法——因此mootools是在哈希中进行的,而不是实际的对象类型。Hash现在被弃用为
对象
-

,但请告诉我如何将el从mootools替换为jquery。我看到el是指mootools中的element.extend。那么如何在jquery.no中扩展元素呢。在
对象中,每个(函数(值,键){})构造el只是.each调用的匿名函数的命名变量(参数)。它与扩展元素无关。在您的例子中,
for(objectname中的var el){regexArray.push(obj[el]);}