Really Understanding Functions in Javascript

Introduction

We keep coming back to how Javascript loves functions. Let’s dig a little deeper. One pattern which you’ll keep bumping into again and again and again is the “module pattern”, which lets you group functions and variables logically to keep your code organized and maintainable.

Learning Outcomes

  • How do you call a function “method-style”?
  • How do you call a function “function-style”?
  • What do #apply and #call do?
  • When should you use a constructor?
  • When are arguments for a function required?
  • How can a function take another function as an argument?
  • How can a function return another function? How do you then run that returned function?
  • How do you indicate an argument isn’t required?
  • How might you access overflowing (extra) arguments?
  • What are surrogates and why are they used?
  • What does it mean to “namespace” your code?
  • How do you namespace your code using modules?

Assignment

  1. Read The Design Of Code: Organizing Javascript from Alistapart up to and including the “Building a Module” section for an introduction to the module pattern.
  2. Read Namespacing and using Modules in JS for a fuller explanation of those two topics. It covers a fair bit of ground, but try to use these patterns in your next project (and all the following ones) and they’ll get ingrained in your head.

Additional Resources

This section contains helpful links to other content. It isn’t required, so consider it supplemental for if you need to dive deeper into something.

Javascript and jQuery

Really Understanding Functions in Javascript

Got questions?

Chat with our friendly Odin community in our Gitter chatrooms!

Open Gitter

Are you interested in a more immersive web development learning experince?

Learn more

Viking Code School

  • 12 weeks

    12 Weeks

  • Fully Online

    Fully Online

  • Mentorship

    Mentorship