News for hackers. Stuff that matters.
Re:Replacing jQuery with D3 by dheera on Friday May 15, 2015 @07:41AM (#9549965)
$ = function(foo) { return d3.selectAll(foo); }
Re:Replacing jQuery with D3 by richardwhiuk on Friday May 15, 2015 @08:24AM (#9550104)
or $ = d3.selectAll; surely?
Re:Replacing jQuery with D3 by prezjordan on Friday May 15, 2015 @10:01AM (#9550595)
You also need to re-bind it to d3.

  $ = d3.selectAll.bind(d3);
Since `this` in the `selectAll` will refer to whatever is before the period. When we reassign to `$` in `$ = d3.selectAll`, we lose that. Silly, isn't it?

Demo: http://jsbin.com/guyisewexu/1/edit?js,console

Re:Replacing jQuery with D3 by chrtze on Friday May 15, 2015 @07:56AM (#9550014)
From my perspective I would rather have $.select() instead of $() because it makes more clear what this function actually does.
Re:Replacing jQuery with D3 by ape4 on Friday May 15, 2015 @08:12AM (#9550061)
Future maintainers will hate that.
Re:Replacing jQuery with D3 by Roboprog on Friday May 15, 2015 @11:45AM (#9551335)
Done as a global, then probably, yeah. If it's assigned at the beginning of a function as a local var, then used 5 or 6 times, probably no harm done.