I happened to review the following code today
var triggerWindowResize = $.fn.resize.bind($($window));
var redraw = $timeout.bind(null, triggerWindowResize);
And I thought: that's not how I would do it; I would do it like that
var triggerWindowResize = () => $(window).resize();
var redraw = () => $timeout(triggerWindowResize);
I believe the =>
version is better mostly because it makes it clearer what the code is supposed to do. But of course, there may be other things I'm not taking into account here.
Ignoring the fact these functions could be called with a different number of arguments, which do you think is better? And should there be a coding style that says always use one or the other?
We do use both .bind
and =>
in various parts of our code, so browser support etc. is not relevant here.