title: JavaScript class creation with private members
body: <p>I'm working on a utility to create classes in javascript.
  And it works, the problem is how to define private attributes.</p>
  
  <p>This is the code</p>
  
  <pre><code>var OO = {
  
      Class:function(){
  
          var len = arguments.length;
          var data = arguments[len-1];
  
  
  
          var Klass;
          if (data.constructor === Object){
              Klass = function (){};
  
          } else {
              Klass = data.constructor;
              delete data.constructor;                
          }
  
  
  
          OO.extend(Klass.prototype,data); //Classic Extend Method
  
  
          return Klass;
  
  
      },
  //Simple extend method, just what I need in this case
      extend: function(target, source){
              var prop;
              for (prop in source)
                  target[prop] = source [prop];
  
      }
  }
  </code></pre>
  
  <p>This is how it works</p>
  
  <pre><code>// first create a class
  var person = OO.Class ({
  constructor: function (name, age) {
  this.name = name;
  this.age = age;
  },
  
  name:'',
  age:'',
  
  getName: function () {
  return this.name;
  },
  
  getAge: function () {
  return this.age;
  }
  
  });
  </code></pre>
  
  <p>And here is the instance</p>
  
  <pre><code>var one = new Person ('josh', 22);
  </code></pre>
  
  <p>And the problem:</p>
  
  <pre><code>one.age / / returns 22
  one.name / / returns josh
  </code></pre>
  
  <p><strong>What I need is that these properties can only be accessed by methods like getName () and getAge ()</strong></p>
  
  <p><strong>EDIT1</strong>: Added Extend Function </p>