02 - First Class Functions#

functions are first-class#

const hi = name => `Hi, ${name}`;
const greet = name => hi(name);

// → "Hi, Ahsoka"

There is a big no-no in greet’s definition. Something is reduntant. Explain.

Functions are first-class in ECMAScript. If greet just gets an argument and merely forwards it to hi, then there is no need to make greet take that parameter and pass it along to hi. We can just as well do this:

const greet = hi;

The result is the same, and we didn’t create an unnecessary step in the wiring up of functions.

Read more about the useless use of functions in JavaScript.

controller and views#

const BlogController = {
  create(attrs) { return Db.create(attrs); },

Following the same train of thought of the question above, how can we simplify this to avoid receiving “The Useless Use of Functions Award”‽

const BlogController = {
  create: Db.create,

If Db.create takes an attributes parameter, then we can just make create be a reference to Db.create and the result is the same. And no awards.