I'm trying to understand the source code for d3 selectAll and I don't understand the line following my comment below.
I can see how there is a closure on the selector string and that this
is set to node when d3_selectAll is invoked, but how are the other three arguments in the call
consumed?
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);
};
}
This is only relevant in the context of subselections and explained in the 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.
In particular, if the selector is not a function, these arguments are simply ignored (function declaration at the end with no arguments).
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.