d3.js库的选择器实现
将d3.v2.js1383行附近代码转换如下:
var d3_select = function(s, n) { return n.querySelector(s); } var d3_selectAll = function(s, n) { return n.querySelectorAll(s); } var d3_selectRoot = document.documentElement; var d3_selectMatcher = d3_selectRoot.matchesSelector || d3_selectRoot.webkitMatchesSelector ||
d3_selectRoot.mozMatchesSelector || d3_selectRoot.msMatchesSelector || d3_selectRoot.oMatchesSelector; var d3_selectMatches = function(n, s) { return d3_selectMatcher.call(n, s); };
在Chrome里使用开发者工具里使用控制台实践:
document; document.documentElement; document.documentElement.webkitMatchesSelector; document.documentElement.webkitMatchesSelector(.call/.caller);
可以查看相关详情,并对webkit内核作简要了解。