title: Overriding methods using Javascript module pattern
body: <p>I've got a browser addon I've been maintaining for 5 years, and I'd like to share some common code between the Firefox and Chrome versions.</p>
  
  <p>I decided to go with the <a href="http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth" rel="nofollow">Javascript Module Pattern</a>, and I'm running into a problem with, for example, loading browser-specific preferences, saving data, and other browser-dependent stuff.</p>
  
  <p>What I'd like to do is have the shared code reference virtual, overrideable methods that could be implemented in the derived, browser-specific submodules.</p>
  
  <p>Here's a quick example of what I've got so far, that I've tried in the Firebug console, using the Tight Augmentation method from the article I referenced:</p>
  
  <pre><code>var core = (function(core)
  {
      // PRIVATE METHODS
      var over = function(){ return "core"; };
  
      var foo = function() {
          console.log(over());
      };
  
      // PUBLIC METHODS
      core.over = over;
      core.foo = foo;
  
      return core;
  }(core = core || {}));
  
  
  var ff_specific = (function(base)
  {
      var old_over = base.over;
  
      base.over = function() { return "ff_specific"; };
  
      return base;
  }(core));
  
  core.foo();
  ff_specific.foo();
  </code></pre>
  
  <p>Unfortunately, both calls to foo() seem to print "core", so I think I've got a fundamental misunderstanding of something.</p>
  
  <p>Essentially, I'm wanting to be able to call:</p>
  
  <pre><code>get_preference(key)
  set_preference(key, value)
  load_data(key)
  save_data(key, value)
  </code></pre>
  
  <p>and have each browser do their own thing. Is this possible? Is there a better way to do it?</p>