title: How to namespace our JS for use with the Rails asset pipeline
body: <p>I understand the reasoning behind the rails 3.1 asset pipeline: we compile all the JS in a neat, cacheable file to improve performance. Great we want that.</p>
  
  <p>However, loading everything also means we've got to be very careful that we not use a certain ID or class on multiple pages, if we have some JS attached to it. Or else, the JS will fire on both pages, since its always loaded.</p>
  
  <p>Now, what we want to achieve is the following:<br>
  * we want to keep everything in a single JS file (we know how we can load files separately, just don't want that)<br>
  * we want to namespace the JS in each <code>controller_name.js</code> so it's only loaded when the appropriate namespace is initialized<br>
  * we want to initialize the appropriate namespace by reading the current controller from say a data-attribute on the <code>&lt;body&gt;</code> tag of our layout</p>
  
  <p>The problem is: we don't have a good idea how to implement in JS. Particularly, how should we namespace the JS and then dynamically initialize it based on the contents of a HTML tag..</p>
  
  <p>Any help is greatly appreciated!</p>