26

Pass by reference, do not wrap needlessly

// Bad
takesCallback(function (data) {
// Literally all this function does
processData(data)
}

// Good
takesCallback(processData)

I see this all the time, especially with jr devs.

Comments
  • 2
    God it annoys me so much when people don't do that. Also not enough people know about partial function application
  • 1
    @brukernavn32 agreed. I have been teaching my co-workers more functional programming patterns.
  • 1
    Need moar memory..
  • 0
    Thing is, most people switching from a OOP language (eg Java /C#) usually thinks structurally like the bad example.

    What you might want to highlight is that a function is an object in javascript. In fact, everything is an object, that's how it works.
  • 1
    @kileak primitives aren't objects ;) I know what you're saying though
  • 1
    True @kileak. In most modern languages functions are first class objects (python, js etc). IMO that's what makes it fun though.
  • 0
    @ecmawizard haha well yeah. But null and undefined being objects kinda blew my mind when I found out.
  • 0
    @kileak null and undefined are primitives.
Add Comment