学习中遇到难懂的代码。。希望有人能解释一下。。
我是新手,看书的时候碰到一段代码,不大明白。。希望有好心人能解释一下。。谢谢。。书名:The Art & Science of JavaScript
其中的第五章,Metaprogramming
程序代码:['forEach', 'map', 'filter', 'slice', 'concat'].forEach(function(func) {
// test if it exists already and only create if it doesn't
if (!Array[func]) Array[func] = function(object) {
// use the call trick to slice() the first argument off the argument list
// as that is going to be the object we operate on
var newArgs = Array.prototype.slice.call(arguments, 1);
// call the array function with object as this with the arguments we just created
return this.prototype[func].apply(object, newArgs);
}
});
前面两句我明白是什么意思,从['forEach', 'map', 'filter', 'slice', 'concat']这个数列循环,每一个都赋一个方法,但是function(object)中那个object parameter 我就不知道是用来干吗的,然后后面newArgs就变成了['map', 'filter', 'slice', 'concat'],return后面又不明白了。。






