title: Converting C# class to JavaScript
body: <p>Take a look at this basic class:</p>
  
  <pre><code>namespace AcmeWeb
  {
      public string FirstName { get; set; }
  
      public class Person 
      {
          public Person(string firstName, string lastName) 
          {
              if (String.IsNullOrEmpty(firstName))
              {
                  throw new ArgumentNullException(firstName);
              }
  
              this.FirstName = firstName;
          }
      }
  }
  </code></pre>
  
  <p>What's the best translation of this into JavaScript?</p>
  
  <p>This is what I'm thinking:</p>
  
  <pre><code>(function(namespace) {
  
      namespace.Person = function(firstName, lastName) {
  
          // Constructor
  
          (function() {
              if (!firstName) {
                  throw "'firstName' argument cannot be null or empty";
              }
          })();
  
          // Private memberts
  
          var _ = {
              firstName: firstName
          };
  
          // Public members
  
          this.firstName = function(value) {
              if (typeof(value) === "undefined") {
                  return _.firstName;
              }
              else {
                  _.firstName = value;
                  return this;
              }
          };
  
      };
  
  })(AcmeWeb);
  </code></pre>