Peter Lyons

Sep 03, 2015

Eliminate Useless Callback Wrappers in JavaScript

Just a quick tip from some code I encountered today. Instead of this:

function outerFunc (callback) {
  doSomething(42, function (err) {
    callback(err)
  })
}

Eliminate the useless callback wrapper function:

function outerFunc (callback) {
  doSomething(42, callback)
}

It's more concise and more efficient and entirely equivalent.