The complete code can be found here: http://www.webdeveloper.com/forum/showthread.php?t=224180#6 This emulates jquery like functionality. The next part defines the methods
//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
I get the above part. This is, of course, a part of a closure. I can’t seem to understand the next part and how calling X.hide() calls the corresponding method in X. If someone would take the time to explain this
//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;
1 Answer