title: How to JSON.stringify a user-defined class in Javascript?
body: <p>JSON.stringify() works on literal objects, such as:</p>
  
  <pre><code>var myObjectLiteral = {
      a : "1a",
      b : "1b",
      c : 100,
      d : {
          da : "1da",
          dc : 200
      }
  };
  var myObjectLiteralSerialized = JSON.stringify(myObjectLiteral); 
  </code></pre>
  
  <p>myObjectLiteralSerialized is assigned,
    "{"a":"1a","b":"1b","c":100,"d":{"da":"1da","dc":200}}"
  as expected.</p>
  
  <p>But, if I define the class with a ctor like this,</p>
  
  <pre><code>    function MyClass() {
      var a = "1a";
      var b = "1b";
      var c = 100;
      var d = {
          da : "1da",
          dc : 200
      };
  };
  
  
  var myObject = new MyClass;
  var myObjectSerialized = JSON.stringify(myObject);
  </code></pre>
  
  <p>then myObjectSerialized is set to the empty string, "".</p>
  
  <p>I think the reason is because the class version ends up being the prototype of the instantiated class which makes it's properties "owned" by the prototype and JSON will only stringify props owned by the instance object, myObject.</p>
  
  <p>Is there a simple way to get my classes into JSON strings w/o writing a bunch of custom code?</p>