有人能解释一下这部分是怎么回事吗
Can someone explain how this part
完整的代码可以在这里找到: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;
相关文章:
- 有人可以向我解释一下代码的JavaScript / Ajax部分是做什么的
- 谁能解释一下这句话的意思吗;var upload_file_count_text=+filenames.length++
- 为什么这只适用于身体部分而不是头部
- 有人可以解释一下这段代码在做什么吗?调用 Class.create() 时实际会发生什么
- 在 Nodejs 中,如果你先调用 cb,那么这会导致函数的其余部分执行吗?
- 如何做到这一点可以点击 显示内容 部分
- Javascript - 有人可以解释一下这段代码吗?
- 什么'It’这是显示元素的一部分但隐藏其余部分的好方法
- 有人能给我解释一下这个HTML/Javascript部分吗
- Django民意测验教程第3部分:Polls/templates/Polls/index.html-这段代码是什么?它&
- Javascript'这'参考资料-有人能解释一下这个简单的例子吗
- 有人能解释一下这部分是怎么回事吗
- jQuery插件|为什么不;这部分不起作用
- 这部分代码在“Pro JavaScript技术”的JS addEvent函数实现中的目的是什么?
- PHP:检测字符串是否包含JavaScript/jQuery代码,并删除这部分代码
- Pro AngularJS -你能帮我解释一下这部分代码吗?
- 如何使这部分代码不在Safari中执行
- 如何将这部分Python转换为惯用的Javascript
- 这部分PHP和CSS需要JavaScript吗?或者只使用CSS
- Internet Explorer 8中出现Javascript/Ajax错误消息!顺便说一下,这还不是最令人震惊的部分