title: JavaScript: Prevent Array.push()
body: <p>I have a sealed object with an array member on which I want to prevent direct pushes.</p>
  
  <pre><code>var myModule = (function () {
      "use strict";
      var a = (function () {
          var _b = {},
              _c = _c = "",
              _d = [];
          Object.defineProperty(_b, "c", {
              get: function () { return _c; }
          });
          Object.defineProperty(_b, "d", {
              get { return _d; }
          });
          _b.addD = function (newD) {
              _d.push(newD);
          };
          Object.seal(_b);
          return _b;
      }());
      var _something = { B: _b };
      return {
          Something: _something,
          AddD: _b.addD
      };
  }());
  
  myModule.Something.c = "blah"; // doesn't update = WIN!!
  myModule.AddD({}); // pushed = WIN!
  myModule.Something.d.push({}); // pushed = sadness
  </code></pre>
  
  <p>How can I prevent the push?</p>
  
  <p><strong>UPDATE:</strong></p>
  
  <p>Thanks for all the thoughts.  I eventually need the JSON to send to the server.  It looks like I might need to use an object for the array then figure out a way to generate and return the JSON needed, or change <em>_something</em> to use .slice().  Will play and report.</p>