我正在尝试理解 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);
};
}
最佳答案
这仅在子选择的上下文中相关,并在 documentation 中进行了解释:
The selector may also be specified as a function that returns an array of elements (or a NodeList), or the empty array if there are no matching elements. In this case, the specified selector is invoked in the same manner as other operator functions, being passed the current datum d and index i , with the this context as the current DOM element.
特别是,如果选择器不是函数,这些参数将被简单地忽略(函数声明末尾没有参数)。
关于javascript - d3 selectAll 源代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28927790/