ga-wdi-boston / api-token-auth

Other
4 stars 154 forks source link

Create functions with `function` keyword? #26

Open gaand opened 7 years ago

gaand commented 7 years ago

Avoid oneliner arrow functions and the time and confusion that result?

so replace

const signIn = (data) =>
  $.ajax({
    // ...
  });

with

const signIn = function (data) {
  return $.ajax({
    // ...
  });
};
jrhorn424 commented 7 years ago

I'm OK with this. Any reason to favor function () {} over () => { } (with explicit block)?

gaand commented 7 years ago

Cognitive load, in part. If fat arrows are for anonymous single expression functions (mostly) and keyword functions are for everything else, less to remember.

Also, event handlers only get the correct this if you use function (unless you're doing more sophisticated stuff that can make use of lexical binding and only dealing with the event object to reference the DOM).