title: JavaScript Module Pattern - Protected members?
body: <p>Hullo! This is my first question!</p>
  
  <p>I am experimenting with the module pattern promoted by Doug Crockford and others. Mostly very happy with it so far, but I am a little unsure about the best way of handling a certain inheritance pattern.</p>
  
  <p>I have it boiled down to a bare bones case using cat and mammal, although my actual intention is to make objects for a tile based game in canvas. </p>
  
  <p>But here is my bare bones 'animals' case using a browser alert:</p>
  
  <pre><code>var ZOO = ZOO || {};
  //
  ZOO.mammal = function () {
     "use strict";
     var voice = "squeak.mp3", // default mammal sound
        utter = function () {
           window.alert(this.voice);
        };
  //
     // public interface
     return {
        utter: utter,
        voice: voice
     };
  };
  //
  ZOO.cat = function () {
     "use strict";
     // hook up ancestor
     var thisCat = ZOO.mammal();
     thisCat.voice = "miaw.mp3";
     return thisCat;
  };
  //
  var felix = ZOO.cat();
  felix.utter();
  </code></pre>
  
  <p>What bothers me about this approach is that I have had to make <code>voice</code> a public property so that cat can modify it.</p>
  
  <p>What I really want is something like 'protected' visibility (from Java, ActionScript etc.), so that <code>cat</code> can modify <code>voice</code> without anyone with access to <code>felix</code> being able to modify it.</p>
  
  <p>Is there a solution?</p>