title: How can I stub/mock a function in the javascript global namespace
body: <p>I'm trying to stub/mock/override a function call during testing which writes a log to a DB.</p>
  
  <pre><code>function logit(msg) {
    writeMessageToDb(msg);
  }
  
  function tryingToTestThisFunction(){
    var error = processSomething();
    if (error) {
      logit(error);
    }
  }
  </code></pre>
  
  <p>I'd like <code>logit()</code> to simply print to the console during testing...and doing a "<code>isTesting()</code>" if/else block inside the <code>logit()</code> function is not an option.  </p>
  
  <p>Is this possible without including some additional mocking framework.  I'm currently using <code>JsTestDriver</code> for unit testing and have not had a chance to evaluate any mocking frameworks.  An ideal solution at the moment would be to handle this without another framework. </p>