title: Cloning a TypeScript Object
body: <p>I have a typescript class</p>
  
  <pre><code>export class Restaurant {
  
    constructor ( private id: string, private name: string ) {
  
    }
  
    public getId() : string {
      return this.id;
    }
  
    public setId(_id : string) {
      this.id = _id;
    }
  
    public getName () {
      return this.name;
    }
  
    public setName ( _name:string ) {
      this.name = _name;
    }
  
  }
  </code></pre>
  
  <p>I then have an instance of this class ( this is an example ):</p>
  
  <pre><code>restaurant:Restaurant = new Restaurant(1,"TestRest");
  </code></pre>
  
  <p>I then store this restaurant object in some sort of cache</p>
  
  <pre><code>cache.store( restaurant );
  </code></pre>
  
  <p>then later in my application I get the restaurant back</p>
  
  <pre><code>var restToEdit = cache.get( "1" );
  restToEdit.setName( "NewName" );
  </code></pre>
  
  <p>But because of javascripts pass by reference on objects, the changes I make to restToEdit also get saved in the restaurant that is in the cache.</p>
  
  <p>I basically want the restaurant in the cache to be a totally different instance to the restToEdit. </p>
  
  <p>I have tried using jQuery.clone and extend, but it doesn't seem to work and I think this is because of it being a typescript object. Or will that not matter?</p>
  
  <p>Any answers on how to clone this object would be appreciated</p>
  
  <p>Thanks</p>