title: Clone Object without reference javascript
body: <p>I have a big object with much data. And i want to clone this in other variable. When i set some param of the instance B has the same result in the original object:</p>
  
  <pre><code>var obj = {a: 25, b: 50, c: 75};
  var A = obj;
  var B = obj;
  
  A.a = 30;
  B.a = 40;
  
  alert(obj.a + " " + A.a + " " + B.a); // 40 40 40
  </code></pre>
  
  <p>My output should be 25 30 40.
  Any ideas?</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>Thanks Everyone. I change the code of dystroy and this is my result:</p>
  
  <pre><code>Object.prototype.clone = Array.prototype.clone = function()
  {
      if (Object.prototype.toString.call(this) === '[object Array]')
      {
          var clone = [];
          for (var i=0; i&lt;this.length; i++)
              clone[i] = this[i].clone();
  
          return clone;
      } 
      else if (typeof(this)=="object")
      {
          var clone = {};
          for (var prop in this)
              if (this.hasOwnProperty(prop))
                  clone[prop] = this[prop].clone();
  
          return clone;
      }
      else
          return this;
  }
  
  var obj = {a: 25, b: 50, c: 75};
  var A = obj.clone();
  var B = obj.clone();
  A.a = 30;
  B.a = 40;
  alert(obj.a + " " + A.a + " " + B.a);
  
  var arr = [25, 50, 75];
  var C = arr.clone();
  var D = arr.clone();
  C[0] = 30;
  D[0] = 40;
  alert(arr[0] + " " + C[0] + " " + D[0]);
  </code></pre>