title: What is the right way to wire together 2 javascript objects?
body: <p>I'm currently facing a conundrum: What is the right way to wire together 2 javascript objects?  </p>
  
  <p>Imagine an application like a text editor with several different files.  I have some HTML page that represents the view for the notebook. I have a file notebook.js that contains class definitions for NotebookController and Notebook View.</p>
  
  <p>NotebookControler object responsible for performing business logic on the Notebook like "Save Notebook," "Load Notebook," "New Notebook."  NotebookView is responsible for managing the HTML that is used for presentation.  It does low level stuff like "get/set notebook body" "get/set notebook name." It also listens for DOM events (onClick) and fires business events (saveNotebook). This is my attempt at the Passive View pattern.   </p>
  
  <p>I want my javascript client-side code to be object-oriented, separated concerns, and unit-testable.  I want to test NotebookController with a mock NotebookView and vice versa.  This means that I can't just instantiate a NotebookView inside the NotebookController.  So do I </p>
  
  <ul>
  <li>Put some logic in my notebook.js that wires the 2 together</li>
  <li>Have a global function in my application that knows to instantiate one of each and wire them together</li>
  <li>Use Dependency Injection, either a home-grown one or something like SquirrelIoc</li>
  </ul>
  
  <p>In Java, the choice is a natural one: use Spring.  But that doesn't seem very JavaScript-y. What's the right thing to do?</p>