title: Casting an object to a custom class
body: <p>I'm developing a HTML 5 application.</p>
  
  <p>In Javascript I have defined a custom class and a HashTable implementation:</p>
  
  <pre><code>function Card(newId, newName, newDescription)
  {
      this.id = newId;
      this.name = newName;
      this.description = newDescription;
  }
  
  function HashTable()
  {
      var hashTableItems = {};
  
      this.SetItem = function(key, value)
      {
          hashTableItems[key] = value;
      }
  
      this.GetItem = function(key)
      {
          return hashTableItems[key];
      }
  }
  </code></pre>
  
  <p>I use HashTable to add Card's objects. I use this code to add cards:</p>
  
  <pre><code>...
  var card = new Card(id, name, description);
  
  $.viacognitaspace.cards.SetItem(id, card);
  ...
  </code></pre>
  
  <p>My problem is when I call HashTable.GetItem and I don't know how to cast object returned to Card class.</p>
  
  <pre><code>var cardObject = $.viacognitaspace.cards.GetItem(cardNumber);
  </code></pre>
  
  <p>Here, <code>cardObject</code> is undefined.</p>
  
  <p>If I do this:</p>
  
  <pre><code>$('#cardName').text(cardObject.name);
  </code></pre>
  
  <p>I get an error.</p>
  
  <p>How can I fix this?</p>