我试图理解source code for d3 selectAll 我在下面的评论中不理解这一行。
我可以看到选择器字符串是如何闭包的,并且在调用d3_selectAll时this
被设置为节点,但call
中的其他三个参数如何被消耗?
import "../core/array";
import "selection";
d3_selectionPrototype.selectAll = function(selector) {
var subgroups = [],
subgroup,
node;
selector = d3_selection_selectorAll(selector);
for (var j = -1, m = this.length; ++j < m;) {
for (var group = this[j], i = -1, n = group.length; ++i < n;) {
if (node = group[i]) {
//***where are node.__data__, i, j consumed?***
subgroups.push(subgroup = d3_array(selector.call(node, node.__data__, i, j)));
subgroup.parentNode = node;
}
}
}
return d3_selection(subgroups);
};
function d3_selection_selectorAll(selector) {
return typeof selector === "function" ? selector : function() {
return d3_selectAll(selector, this);
};
}
答案 0 :(得分:2)
这仅与子选择的上下文相关,并在documentation:
中进行了解释选择器也可以指定为返回元素数组(或NodeList)的函数,如果没有匹配元素则指定为空数组。在这种情况下,以与其他运算符函数相同的方式调用指定的选择器,传递当前数据d和索引i,并将此上下文作为当前DOM元素。
特别是,如果选择器不一个函数,那么这些参数将被忽略(最后没有参数的函数声明)。