Using the Javascript Module Pattern, and more modern JS practices, with Drupal

The JavaScript Module pattern uses immediately-invoked functional expressions (IIFE) that return objects, that include closures. This provides a way of wrapping various public and private methods and variables in a "module". This prevents them from "leaking" into the global name scope and cluttering it up or worse, colliding with other code. With this pattern only a public "API" is returned, while maintaining privacy on everything else. Additionally, I'll discuss how to split up and organize your js files for maintainability and reuse.

  • the advantages of using the JavaScript Module Pattern for better, cleaner code
  • practical implementation using Grunt, grunt-contrib-concat or Bower & grunt-bower-concat
  • using it with Drupal.behaviors, jsHint, jQuery, etc.
  • how-to's with introduction to sub-patterns like: Module Export, Public and Private, Global Import, Loose Augmentation, etc.

I originally gave this talk at LA Drupal Camp 8/2015  (slides will be updated based on feedback, plus more D8).

BADcamp15 slides

Session track:

Session skill level:

Session speaker(s): 
Session date and time: 
Sunday, October 25, 2015 - 1:30pm

Session time slot:

Session room: