Course List >> Javascript and jQuery >> Deeper into Javascript >> 5: Really Understanding Functions in Javascript
Scroll up or hover over the breadcrumbs to view the navigation bar

Really Understanding Functions in Javascript

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.

Points to Ponder

  • 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?

Your 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

From the creators of The Odin Project...

The Viking Code School
Viking ad 180x150