title: Duplicate/Clone Javascript Object
body: <p>Is there a way to clone a javascript object? Not a DOM element, but an object with a specific constructor. For instance lets say I have a phone number object:</p>
  
  <pre><code>function PhoneNumber(number, type) {
      this.number = number;
      this.type = type;
  }
  
  var phoneObj1 = new PhoneNumber('1111111111', 'Home');
  var phoneObj2 = //Copy of phoneObj1, but unique so I can set other parameters if necessary.
  </code></pre>
  
  <p>jQuery solves this problem for me with extend.</p>
  
  <pre><code>var phoneObj2 = $.extend({}, phoneObj1);
  </code></pre>
  
  <p>But it returns a generic object:</p>
  
  <pre><code>Object{number:'1111111111' type:'Home'}
  </code></pre>
  
  <p>Instead of with the Phone Number constructor name. I need a way of passing in the original phoneObj1's constructor without actually writing new PhoneNumber() in the extend, because the code this is being used in is used by many different types of Objects so at any given time I don't know the exact constructor that should be used except for the fact that I have an object to reference.</p>
  
  <pre><code>var phoneObj2 = $.extend(new PhoneNumber(), phoneObj1); //I CANNOT do this!
  
  //Maybe something like this?
  var phoneObj2 = $.extend(new phoneObj1.constructor.name, phoneObj1); //This throws an error.
  </code></pre>