In this question ,答案代码之一是:
var arrays = [[1,2,3,4,5,6], [1,1,1,1,1,1], [2,2,2,2,2,2]];
_.map(_.zip.apply(_, arrays), function(pieces) {
return _.reduce(pieces, function(m, p) {return m+p;}, 0);
});
在 apply(_, arrays)
中,我不明白 _
有什么关系。
最佳答案
apply
调用相当于
_.zip([1,2,3,4,5,6], [1,1,1,1,1,1], [2,2,2,2,2,2])
apply
的第一个参数确保使用正确的上下文 (this
value) 调用 zip
,通常是 _
,Underscore 的命名空间- constructor-function -目的。实际上它没有在 zip
函数中使用,所以我们可以省略它并传递 null
或 undefined
代替。
关于underscore.js - _ 在 apply() 中的含义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19404032/