jQuery
$('.foo').find('.bar');
D3 d3.selectAll('.foo').selectAll('.bar');
The D3 API consistency is so juicy and delicious.jQuery
$('.foo').find('.bar');
D3 d3.selectAll('.foo').selectAll('.bar');
The D3 API consistency is so juicy and delicious. $.find('.foo').find('.bar')
It's just a different way of invoking it. The short-hand is more convenient since it accepts a selector as well as a plain DOM node and converts that to a jQuery elements. This makes things very easy and idiomatic.And don't even get me started on how jQuery hijacks `this` in callbacks...
I can't understand though why you would claim to dislike jQuery providing you a useful 'this'. You prefer to receive the window object?
Useful but poorly named isn't useful.
> I can't understand though why you would claim to dislike jQuery providing you a useful 'this'.
I prefer programming language libraries to work according to the semantics of the underlying programming language. Is that so wrong?
Nearly every programming language in existence has some feature(s) that you can shoot yourself in the foot with. Does that mean you should do it?
$('.foo').append('<div class="bar" data-selected="true"/>');
in d3 I have to go the long way:
d3.select('.foo') .append('div') .classed('bar', true) .attr('data-selected', true);
I have recently worked a lot with this plugin https://github.com/gka/d3-jetpack which includes some very nice helper functions!
But if you can do that...
d3.select('.foo').append(d3.functor(node));
$('.foo .bar');
But I would assume you could do the same in D3?