title: Does this getter-setter Closure have a good reason to declare it's privates in it's inner object this way?
body: <p>I was following this: </p>
  
  <p><a href="http://www.samselikoff.com/blog/some-Javascript-constructor-patterns/" rel="nofollow">Javascript constructor patterns</a> - scroll to "Closures with getter-setters (D3.js, jQuery))"</p>
  
  <p>and I was confused by the way <code>my</code> is declared:</p>
  
  <pre><code>function Person(firstName, lastName) {
    var _firstName = firstName,                  // private 
        _lastName = lastName;                    // private 
  
    var my = {
      firstName: _firstName,                     // &lt;- why?
      lastName: _lastName                        // &lt;- why?
    };                                           // var my = {};?
  
    my.fullName = function() {                   
      return _firstName + ' ' + _lastName;       // a toString() wannabe
    };
  
    // Getter/setters
    my.firstName = function(value) {             
      if (!arguments.length) return _firstName;  // getter
      _firstName = value;                        // setter   
  
      return my; // enable "method chaining" ...
    };
  
    my.lastName = function(value) {              
      if (!arguments.length) return _lastName;   // getter
      _lastName = value;                         // setter  
  
      return my; // ... so mark.firstName('Samuel').lastName('Clemens'); works
    };
  
    return my; // expose inner object but not the private instance variables
  }
  </code></pre>
  
  <p>The side comments in the section above were added to expose my thinking.</p>
  
  <pre><code>//Use it like this:
  
  var mark = Person('Mark', 'Twain'); // note: no `new` keyword!
  
  mark.firstName('Samuel');
  mark.lastName('Clemens');
  
  mark.fullName(); // Samuel Clemens
  </code></pre>
  
  <p><code>var my = {};</code> seems to work when this is tested in chrome's console.  This code is meant to support encapsulation. Testing after this change hasn't revealed any new way into the privates or broken functionality.  But I worry there some magic I'm missing that required this.  </p>
  
  <p>Please check my thinking.  Isn't the _firstName in my.firstName just getting stepped on when it's redefined as a getter/setter function?  Am I exposing or breaking something by switching to <code>var my = {};</code>?</p>
  
  <p>The <strong>How does this work?</strong> section says:</p>
  
  <blockquote>
    <p>"Typically, when a function finishes executing, the variables declared
    within that function fall out of scope and get destroyed. But there's
    an exception: if any code outside the function holds a reference to
    these variables after the function finishes executing, they won't be
    cleaned up. Instead, a closure will be formed, and those variables
    will remain in memory."</p>
    
    <p>"In the example above, since the Person constructor function returns
    the inner object my, and since my refers to the local variables
    _firstName and _lastName (both in the getter/setters and in the fullName method), the variables are not destroyed. When the
    getter/setters are invoked, they are operating on those same local
    variables."</p>
  </blockquote>