有人能解释一下这部分是怎么回事吗

Can someone explain how this part

本文关键字:这部分 一下 怎么回事 能解释      更新时间:2023-09-26

完整的代码可以在这里找到:http://www.webdeveloper.com/forum/showthread.php?t=224180#6这模拟了类似jquery的功能。下一部分定义的方法

//define some methods for the utility:
var meths={
    hide:function(a){if(a)a.style.display="none";},
    show:function(a){if(a)a.style.display="";},
    remove:function(a){if(a)a.parentNode.removeChild(a);},
    color:function(a){a.style.color=this||a.style.color;},
    size:function(a){if(a)a.style.fontSize=this||a.style.fontSize;}
};//end meths

我明白上面的部分。当然,这是结束的一部分。我似乎不明白下一部分,也不明白调用X.hide()是如何调用X中相应的方法的。如果有人愿意花时间解释这个

//bind the methods to the collection array:
for(var meth in meths)
  (function(n,m){
    output[n]=function(x){output.map(m,x); return output;}
  }(meth, meths[meth]));//next method
return output;
// Earlier in the code, 'output' was defined as an array...
var output = [];
// For each key in the object 'meths'...
// (which was defined as an object of methods)
for (var meth in meths)
    // Execute the closure... (using the key as 'n' and the method as 'm')
    (function(n,m){
        // Using the key, assign to the 'output' array a function that
        // maps the current method that we're on, for each element in the array.
        // (Array.map() runs a function, given as the first argument, for each
        // element in an array)
        //
        // In this case, the 'x' in the function is the placeholder for a
        // parameter. Like jQuery, this returns the modified output for chaining.
        output[n] = function(x){ output.map(m,x); return output; };
    })(meth, meths[meth]); // Using the key and method
return output;