title: Javascript Modular Prototype Pattern
body: <p>The problem with functional inheritance is that if you want to create many instances then it will be slow because the functions have to be declared every time.</p>
  
  <p>The problem with prototypal inheritance is that there is no way to truly have private variables.</p>
  
  <p>Is it possible to mix these two together and get the best of both worlds? Here is my attempt using both prototypes and the singleton pattern combined:</p>
  
  <pre><code>var Animal = (function () {
    var secret = "My Secret";
  
    var _Animal = function (type) {
      this.type = type;
    }
    _Animal.prototype = {
      some_property: 123,
      getSecret: function () {
        return secret;
      }
    };
  
    return _Animal;
  }());
  
  var cat = new Animal("cat");
  
  cat.some_property; // 123
  cat.type; // "cat"
  cat.getSecret(); // "My Secret"
  </code></pre>
  
  <p>Is there any drawbacks of using this pattern? Security? Efficiency? Is there a similar pattern out there that already exists?</p>